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
2 4 6 | [System.Windows.Forms.SendKeys]::SendWait('Hi') [System.Windows.Forms.SendKeys]::SendWait('{ENTER}') [System.Windows.Forms.SendKeys]::SendWait('{RIGHT 5}') |
More information
CATEGORÍAS
ETIQUETAS
MÁS
Context:This morning I was standing with Ben Gelens at the coffee machine since we’re both at the same customer.
Problem:Someone walked by and asked me if there is a way for PowerShell to ask for a key to press before it continues with the script… like a pause.
Together we replied: Read-Host. However, it seems that this scripter didn’t want a pop-up… which is what Read-Host gives… in PowerShell v2 at least.
In PowerShell 5 (which is what I’ve tested) it does not provide a pop-up. It also isn’t exactly like Press Any Key To Continue since it will only continue after an ENTER.
Solution: Upgrade to the latest and greatest version of Windows (or just upgrade WMF/PowerShell).
Workaround: See below.

Inside a PowerShell prompt you can do the following:
This is maybe a bit much for beginning scripters, so here’s an simpler version:
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
2 4 6 | Exception calling'ReadKey'with'1'argument(s):'The method or operation is not implemented.' +$Host.UI.RawUI.ReadKey([System.Management.Automation.Host.ReadKeyOpt... +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +CategoryInfo:NotSpecified:(:)[],MethodInvocationException |
It seems that the ReadKey method isn’t implemented in the host of Windows PowerShell ISE…
So here’s some code that will offer a bit like the same functionality but in ISE (instead of any key, only ENTER will work):
Yes, Read-Host.
All my endeavours and investigations have led me to one single conclusion: Within Windows PowerShell ISE there is only one way to get functionality that resembles the Press Any Key To Continue behaviour and that is by using Read-Host.
This is because the console in ISE isn’t a console. It resembles one, but it isn’t the PowerShell console.
I don’t know if the terminology is correct, but I think it’s something that emulates a PowerShell console 🙂
Hope you find this information useful.