Powershell Press Any Key To Continue



Introducction

TIMEOUT - Delay that allows the user to press a key and continue immediately. PowerShell: Pause Equivalent bash command (Linux): read -p 'press any key to continue' or ctrl-z & fg. If i press Ok the script execution continues and if i click on Cancel, execution stops at that point but i believe that i not the purpose of read-host ( i expects an input from user ). Is there any cmdlet or procedure to prompt the user to just stop or continue the execution of powershell script. Please let me know, thanks in advance. It is important to note that this method is only available in the PowerShell console this does not work in the PowerShell Integrated Scripting Environment (ISE). A simple example: You might require your script to ask for Yes / No, using the Read-Host would allow the user to type in more than one character and the enter key would have to be pressed.

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