views:

95

answers:

1

PowerShell $OutputEncoding defaults to ASCII. PowerShell by default represents strings in Unicode. When I create scripts using the ISE, they are created in Unicode.

The following command sends text to a file in Unicode: echo Testing > test.txt

When I push these files to GitHub, the code view chokes on them because they aren't UTF-8.

I'm confused about the best solution, with the least amount of work during commit.

I know I could convert each file and then commit, but that seems cockeyed to me. Clearly, I can't change how PowerShell represents strings internally, nor would I want to.

What are others doing?

+2  A: 

ISE preserves an existing file's encoding but when you create a new file with ISE it is always creates the file with Unicode encoding. This has nothing to do with the $OutputEncoding. IIRC it was deemed a bug late in the dev cycle - too late to fix. Anyway, you can work-around this by going to the command window the first time you save a file and execute:

$psISE.CurrentFile.Save([Text.Encoding]::ASCII)

After that, you can just press the Save button.

Keith Hill
That did the trick.
rbellamy