Blocking Interactive Console Apps in the ISE editor

by Dec 12, 2012

The ISE editor in PowerShell 3.0 seems to have an interactive console, but it really isn’t. It is just a simulated console. So any command that requires direct console input will block the ISE forever – like this one:

PS> choice.exe

To prevent problems like this, there is a built-in list of unsupported applications:

PS> $psUnsupportedConsoleApplications
wmic
wmic.exe
cmd
cmd.exe
diskpart
diskpart.exe
edit.com
netsh
netsh.exe
nslookup
nslookup.exe
powershell
powershell.exe

You can add new applications to this internal black list:

PS> $psUnsupportedConsoleApplications.Add('choice') 
PS> $psUnsupportedConsoleApplications.Add('choice.exe')

Now, the ISE will stop executing the listed commands in interactive mode. This also protects you from running scripts that contain commands like this.

(You may want to place this into your profile script (path is listed in $profile) so PowerShell executes them each time it starts)

You can still run them as long as they don’t ask for input:

PS> # this works in the ISE console:
PS> nslookup microsoft.com
PS> # this is blocked:
PS> nslookup

Twitter This Tip! ReTweet this Tip!