PowerShell Genie

Wait-Process

Use Wait-Process to block until one or more processes exit, or until a timeout expires.

Command 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn — Wait-Process

Syntax

1PS> Wait-Process [-Name] <String[]> [[-Timeout] <int32>] [<CommonParameters>]
See the command anatomy

Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

Wait-Process [-Name] <String[]> [[-Timeout] <int32>] [<CommonParameters>]
  1. Stage 1Wait-Process-Name -Timeout

    Try it

    Windows PowerShell

    PowerShell example · browser support is limited.

    Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.

    Interactive simulation · fictional data

    Examples

    Wait-Process -Name notepad

    1PS> Wait-Process -Name notepad -Timeout 30
    Show reference output

    Sample output · fictional data, shaped like the real thing

    (No pipeline output. The selected process exited before the timeout.)

    Wait-Process -Id $p.Id

    1PS> $p = Start-Process notepad -PassThru; Wait-Process -Id $p.Id -Timeout 60
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Handles  NPM(K)  PM(M)  WS(M)  CPU(s)   Id  ProcessName
    -------  ------  -----  -----  ------   --  -----------
    86       12      18.4   27.2   0.08     7344 notepad

    Stop-Service -Name MyApp

    1PS> Stop-Service MyApp; Wait-Process -Name MyApp -Timeout 30; # now replace files
    Show reference output

    Sample output · fictional data, shaped like the real thing

    (No pipeline output. The selected process exited before the timeout.)

    Parameters

    Parameter definitions:

    • -Name
    • -Timeout

    Wait-Process on Microsoft Learn

    Practical use and troubleshooting

    Practical scenario: Use Wait-Process when you need to block until one or more processes exit, or until a timeout expires. Review syntax and sample output, then try an example in the browser lab. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.

    Common error and fix: A timeout means the process has not exited within the allowed interval. Report that condition explicitly and decide whether to keep waiting; do not interpret a timeout as successful completion. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.

    See also: Stop-Process. Stop-Process requests process termination; Wait-Process waits for a process to exit. Waiting does not stop the application and termination is not a graceful application shutdown. Read the linked command before substituting it; similar names do not imply identical inputs or output.

    Wait-Process reference on Microsoft Learn

    Recap

    Wait-Process Use Wait-Process to block until one or more processes exit, or until a timeout expires.

    Next: Get-Process
    Genie guideWait-Process

    Use Wait-Process to block until one or more processes exit, or until a timeout expires. The console below is pre-loaded — run it, then change a value and run it again.