Pausing PowerShell Script Execution

Here's a quick scriptlet that displays a message and also waits for a key to be pressed before the PowerShell script continues.

Rod Trent

June 18, 2013

1 Min Read
Pause

There are various reasons to pause a script. For one, you may need to verify that a section of your script has processed correctly before allowing it to continue. In other cases, you may want to halt the script's execution so you can perform some manual tasks or run a second script to compare results. And, another example might simply be that you want to give the end-user some instructions or allow them to take part in the flow of what is happening on their PC.

Here's a quick scriptlet to add to your own scripts that displays a message and also waits for a key to be pressed before the PowerShell script continues.

 

Write-Host "Press any key to continue …"

$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

 

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