Background
I have a pipe delimited csv file that looks like this:
ColA|ColB|ColC|ColD|ColE|ColF|ColG|ColH|ColI|ColJ|ColK
00000000|000000507|0000000|STATUS|0000|000000|000|0000|00|0000|00000
00000000|000000500|0000000|STATUS|0000|000000|000|0000|00|0000|00000
00000000|000007077|0000000|STATUS|0000|000000|000|0000|00|0000|00000
I want to take ColB on lines with a certain status and put it in a headless csv file like this:
000000507,0000000001,0,0
000000500,0000000001,0,0
000007077,0000000001,0,0
The values 0000000001,0,0 on the end of the line are identical for every item.
The Script
The trimmed down/generic version of the script looks like this:
$infile = Import-Csv ".\incsv.txt" -Delimiter '|'
$outfile = ".\outcsv.txt"
Foreach($inline in $infile){
If($inline.Status -ne 'Some Status'){
$outline = $inline.'ColB' + ',0000000001,0,0'
Add-Content $outfile $outline -Encoding ASCII
}
}
The Problem
The problem is that the new file that is created is about twice the size it should be, and I know it has to do with the encoding. Unfortunately, I can't find an encoding that works. I've tried -Encoding ASCII, -Encoding Default, -Encoding UTF8, but they all are too large.
This wouldn't be an issue, but the program that reads the created text file won't read it correctly.
What I can do, is copy the text from the new file in Notepad, save it as ANSI, and it works fine. ANSI isn't an option in the -Encoding parameter though.
How do I get Powershell to output the correct file type? Is there a better way to approach this?
I've found this Google Groups conversation and this Social TechNet post, but neither one actually worked for me.