Input:

```
1116559   P1303251287   20130325225906CD   13013822   1   0000
1104220   P1303250282   20130325070119CD              1   0000
1064743   P1303251094   20130325191600CD              0   0000
1100819   P1303250369   20130325091722CD              0   0000
1101405   P1303250051   20130325010740CD              2   0000

```

What I get from my attempt:

```
$lines = Get-Content "filenamehere.txt"
ForEach ($x in $lines) {
$y = "$($x[0..9] -join '')|$($x[10..23] -join '')|$($x[24..42] -join '')|
$($x[43..53] -    join '')|$($x[54..57] -join '')|$($x[58..61] -join '')|
$($x[126..138] -join '')"
$z = $y -join '|'
Write-Output $z | Out-File -FilePath "foo.txt" -Append}

```

I get:

```
1116559   |P1303251287   |20130325225906CD   |13013822   |1   |0000|
1104220   |P1303250282   |20130325070119CD   |           |1   |0000|
1064743   |P1303251094   |20130325191600CD   |           |0   |0000|
1100819   |P1303250369   |20130325091722CD   |           |0   |0000|
1101405   |P1303250051   |20130325010740CD   |           |2   |0000|

```

I don't mind the trailing spaces as long as I can get into this format. But "Get-Content" parse my data into an array and importing to SQL gives me an error. Question is, how can I convert this into CSV?

Output should be:

```
1116559|P1303251287|20130325225906CD|13013822|1|0000
1104220|P1303250282|20130325070119CD|        |1|0000
1064743|P1303251094|20130325191600CD|        |0|0000
1100819|P1303250369|20130325091722CD|        |0|0000
1101405|P1303250051|20130325010740CD|        |2|0000

```