31
7
By default, PowerShell in Windows seems to be outputting UTF-16 (e.g., if I do a simple echo hello > hi.txt
, then hi.txt
ends up in UTF-16). I know that I can force this to my desired text encoding by instead doing echo hello | out-file -encoding utf8 hi.txt
, but what I'd like is for that to just be the default when I use the redirection operator. Is there any way to achieve this?
1thanks for the tip for an alternative, doing this from the terminal can be quicker than a text editor sometimes. – Todd Partridge – 2017-06-05T15:24:06.727
In Powershell 6.0, this has been rendered unnecessary - Powershell now defaults to UTF-8 without encoding for redirection. See https://github.com/PowerShell/PowerShell/issues/4878
– kumarharsh – 2018-05-22T11:44:24.487