Wait for user input in PowerShell

Learn how to wait for user to press a key in PowerShell.

John Savill

October 30, 2016

1 Min Read
Wait for user input in PowerShell

Q. How can I pause a PowerShell script until a user presses a key?

A. The two lines of PowerShell below will pause a script until the user presses (and does not have to release) a key.

Write-Host "Press any key to continue ....."$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

 

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like