Using redirection within the script produces a unicode output. How to emit single-byte ASCII text? Using redirection within the script produces a unicode output. How to emit single-byte ASCII text? powershell powershell

Using redirection within the script produces a unicode output. How to emit single-byte ASCII text?


You could change the $OutputEncoding variable before writing to the file. The other option is not to use the > operator, but instead pipe directly to Out-File and use the -Encoding parameter.


The > redirection operator is a "shortcut" to Out-File. Out-File's default encoding is Unicode but you can change it to ASCII, so pipe to Out-File instead:

Get-Content -Encoding ASCII $projFile.FullName |    % { $_ -replace '<FooterText>(.+)</FooterText>', $newFooter } |    Out-File $tmpfile -Encoding ASCII


| sc filename does the trick (sc being an alias for Set-Content)

for >> filename use | ac filename does the trick (ac being an alias for Add-Content)