PowerShell ISE and ASCII Files

If any of you have ever created a file in the PowerShell ISE and then wondered why it doesn’t look right when you open it in some other editor, or try to run it, you’ve just run into a "feature" that I wish were not the default–New files are saved as Unicode files. There’s no problem with you’re working with an existing ASCII file, the ISE will preserve the format. But if you’re creating a new file, it saves as Unicode. Now this has always annoyed me, but I never really did anything about it, just worked around it when I got hit with it. But the other day I came across an old blog post from Doug Finke, a fellow PowerShell MVP. He adds the following line to his ISE $profile:

$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Save File ASCII",{$psISE.CurrentFile.Save([Text.Encoding]::ASCII)}, $null) | out-null

That’s it. One line of code, and there’s a new menu item on the AddOns Menu to solve the problem. Sweet.

(For those who haven’t created an ISE $profile yet, it goes in the same directory as your regular PowerShell $profile, but has the filename: Microsoft.PowerShellISE_profile.ps1. )

Charlie.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>