Waiting for a Keystroke

by Sep 18, 2014

All PowerShell versions, PowerShell Console only

To keep the PowerShell console open when a script is done, you may want to add a “Press Any Key” statement. Here is a way how you can implement this:

Write-Host 'Press Any Key!' -NoNewline
$null = [Console]::ReadKey('?') 

This will work in a real PowerShell console only. It will not work in the ISE editor or any other PowerShell editor that does not use a real console with a real interactive keyboard buffer.

Twitter This Tip! ReTweet this Tip!