PowerTip: Use PowerShell to Wait for a Key Press

Summary: Learn about the Windows PowerShell version of “Pause.”

Hey, Scripting Guy! Question How can I use Windows PowerShell to wait for a key in scripts like I used to use “Pause” in the command console?

Hey, Scripting Guy! Answer Use the $Host variable in the console:

$HOST.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”) | OUT-NULL

Comments (8)

  1. jrv says:

    @Dalmiro –

    It is still there if you need it:

    PS >cmd /c pause

    Works just like it always did.

  2. David Wyatt says:

    In PowerShell v3, Pause is just a simple function.  Even if you're running PowerShell v2, you can add it to a profile or script:

    function Pause


       Read-Host 'Press Enter to continue…' | Out-Null


  3. MockMyBeret says:

    I use this… is your way better?

    If (!($psISE)){"Press any key to continue…";[void][System.Console]::ReadKey($true)}

    And, is there anything wrong with mine? (no flush buffer)

  4. Dalmiro says:

    3 versions already and an upcoming 4th. Put the "Pause" just like it was on command console already 🙂

  5. Vern_Anderson says:

    Hey proxb and Sean,

    if ($PSVersionTable.PSVersion.Major -ge 3) {Get-Command Pause}

  6. I like what david gave, simple and easy to use.. read-host press enter key to continue.. infact I have been using it for long time..

  7. ez4sheezee says:

    The above solution does not seem to work for Powershell ISE, confirmed per the following link: http://connect.microsoft.com/PowerShell/feedback/details/713218/host-ui-rawui-readkey-not-implemented-in-version-3-ctp2

    In addition, someone wrote their function to pause scripts:


    This is similar, but much more verbose than chameleon777.

    Hope this helps someone!

  8. mike says:

    Put the flushbuffer before the readkey and you prevent previously pressed keys from bypassing the pause.