Reputation: 43
I'm using the Powershell cmdlet export-csv to export the results of a sqlserver query to a .txt file. The result rows match my expectations when I view them with a text editor (Notepad), like this:
Account|Representative|Note
But, when I open the file using Binary file format (in TextPad), I see that the result rows are interspersed with extra characters (not sure if they are periods or spaces), like this:
A.c.c.o.u.n.t.|.R.e.p.r.e.s.e.n.t.a.t.i.v.e.|.N.o.t.e.
I've tried specifying different values for export-csv's encoding parameter, including UTF32, UTF8, ASCII, and Unicode, but can't get rid of the extra characters.
I have other methods of generating the file (SSIS package), but would specifically like to get this Powershell option working for the benefit of the group that will support the export.
Thank you in advance for any help you can provide.
Upvotes: 0
Views: 2933
Reputation: 200203
Open the file in Notepad and click File → Save As.... The pre-selected value of the field Encoding will tell you which encoding was used (probably Unicode
). Export-Csv -Encoding ASCII
should take care of that, though. You could also try to recode the file like this:
Get-Content generated.txt | Out-File -Encoding ASCII converted.txt
If that doesn't help, please open the file with a hex editor and update your question with the first couple bytes (first line should suffice).
Upvotes: 2