Wait for user input in PowerShell

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")

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish