Powershell Out-File: Force encoding to Ascii

Question:

I am attempting to normalize a set of TAB-delimited logfiles using Powershell.

Here is the current script:

A snippet of the input & output can be seen here:

http://pastebin.com/uaQadYUC

How can I force the output file to be ascii and not some type of unicode?

***Edit: Further troubleshooting reveals that the input files are actually windows-1252 encoded, which apparently Get-Content cannot handle natively(?)

Answer:

You should be able to use the encoding flag on out-file as in ... | Out-File -encoding ascii myfile.txt. And if you’re using append, make sure all appends use the same encoding or you’ll end up with an unusable file.

Source:

Powershell Out-File: Force encoding to Ascii by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply