How to work around a PowerShell Integrated Scripting Environment Bug

by Doug Finke on July 20, 2009

in Add-on Menu, Bug, ISE, Integrated Scripting Environment, PowerShell

When saving a new file using PowerShell’s ISE it encodes it as Unicode. For existing files the encoding is not changed.

Some editors and viewers are unable to display files with this encoding.

It is a bug and won’t be fixed in time for Windows 7 RTM.

Workarounds

Open the file in a another editor, do a file save as look for the encoding options and choose ANSI.

Another option, execute this in the command pane

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

It will save/resave the file with this encoding going forward.

I’ve added this to my ISE profile so the command is easily accessed from the ISE menu

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

{ 2 comments… read them below or add one }

1 Bernd Kriszio 07.21.09 at 10:44 am

Thanks doug for that hint.
May I add that western european users might prefer

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

That works perfectly for me on a german system. We are not very happy with the pure 7-bit ASCII encoding.

Bernd

2 Bernd Kriszio 07.21.09 at 10:45 am

Thanks dough, great hint.

As german I prefer

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

since here 7-bit ASCII encoding is rather useless.

Bernd

Leave a Comment

You can 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>