Powershell Press Any Key To Continue

Introducction

'Press any key to continue.' GitHub Gist: instantly share code, notes, and snippets. Another simple solution would be to use: Read-Host -Prompt 'Press any key to continue or CTRL+C to quit' I believe this is a better solution to the currently accepted answer because the requirement of hitting enter on the keyboard. I don't believe hitting enter will accept the UI prompt unless that UI element is in focus. Solution 2: Works in PowerShell ISE Here is a simple way to pause the script execution and wait for the user to press the ENTER key to continue. This works for both the PowerShell commandline console as well as in the PowerShell ISE.

Each key is represented by one or more characters. To specify a single keyboard character, use the character itself. For example, to represent the letter A, pass in the string «A» to the method. To represent more than one character, append each additional character to the one preceding it. To represent the letters A, B, and C, specify the parameter as «ABC».

The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses () have special meanings to SendKeys. To specify one of these characters, enclose it within braces ({}). For example, to specify the plus sign, use «{+}». To specify brace characters, use «{{}» and «{}}». Brackets ([ ]) have no special meaning to SendKeys, but you must enclose them in braces. In other applications, brackets do have a special meaning that might be significant when dynamic data exchange (DDE) occurs.

To specify characters that aren’t displayed when you press a key, such as ENTER or TAB, and keys that represent actions rather than characters, use the codes in the following table.

To specify keys combined with any combination of the SHIFT, CTRL, and ALT keys, precede the key code with one or more of the following codes.

Examples

Powershell Press Any Key To Continue Disable

[void]($Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown'))

However, if you were to execute this in PowerShell ISE, you’ll get hit by an error:

Powershell Press Enter Key To Continue