Can you provide the required schema for all columns? You’ve presented new information that wasn’t originally present. I think the substring method on the whole line is not the way to go. You should split on the pipes and then manipulate elements. The PadRight method is great for ensuring short columns are certain widths if your filler characters are the same. Combine that with substring to ensure long columns are certain widths. Here is an example, but since I don’t know your full column schema, I can’t provide something complete.

get-content .\inputfile.txt | Foreach-Object {
    # split columns into an array using pipe delimiter
    $s = $_ -split '\|'
    # first column should be two characters
    $s[0] = $s[0].PadRight(2,' ').SubString(0,2)
    # ninth column should be 5 characters
    $s[8] = $s[8].PadRight(5,' ').SubString(0,5)
    $s -join '|'
} | Set-Content "$PSScriptRoot\OutputFile.txt"
2 Spice ups