Friday, January 04, 2013

"ReadKey Exception" trying to pause PowerShell Script

If you use $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") to pause in a PowerShell script, you get the following error message:
Exception calling "ReadKey" with "1" argument(s): "The method or operation is not implemented."

Reason: You are probably running the PowerShell script in the PowerShell ISE thus the related IO sub-system is unavailable.

Solution: Run the script directly and not from the PowerShell - ISE, it will work as expected.

No comments: