Search code examples
powershell

How do you do a ‘Pause’ with PowerShell 2.0?


OK, I'm losing it. PowerShell is annoying me. I'd like a pause dialog to appear, and it won't.

PS W:\>>> $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Exception calling "ReadKey" with "1" argument(s): "The method or operation is not implemented."
At line:1 char:23
+ $host.UI.RawUI.ReadKey <<<< ("NoEcho")
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Solution

  • cmd /c pause | out-null
    

    (It is not the PowerShell way, but it's so much more elegant.)

    Save trees. Use one-liners.