Wait-Process

Wait for one or more processes to be stopped before accepting more input.

Syntax
      Wait-Process -name string[] [[-Timeout] int] [CommonParameters]
    
      Wait-Process [-id] Int32[] [[-Timeout] int] [CommonParameters]
    
      Wait-Process -inputObject Process[] [[-Timeout] int] [CommonParameters]

Key
   -Name 
       Process name(s)
       Separate multiple process names with commas or use wildcard characters. 

   -id Int32
       Process ID(s) (PID). Use commas to separate multiple PIDs.
       To find the PID of a process, type "get-process".
   
   -inputObject 
       Accept a process object as input to Wait-Process.  
       A variable, command or expression that returns the process object(s)

   -Timeout int
The maximum time, in seconds, that Wait-Process will wait for the processes to stop. When this interval expires, the command displays a non-terminating error that lists the processes that are still running, and ends the wait. CommonParameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable, -OutBuffer -OutVariable.

Wait-Process works only on processes running on the local computer.

Examples

Stop the Notepad process and then wait for the process to be stopped before proceeding with the next command:

PS C:\> $nid = (get-process notepad).id
PS C:\> stop-process -id $nid
PS C:\> wait-process -id $nid


Waits 30 seconds for both the Outlook and Winword processes to stop:

PS C:\> wait-process -name outlook, winword -timeout 30

Show three different methods of specifying a process to the Wait-Process cmdlet:

PS C:\> $p = get-process notepad
PS C:\> wait-process -id $p.id

PS C:\> wait-process -name notepad

PS C:\> wait-process -inputobject $p

“So what do we do? Anything. Something. So long as we just don't sit there. If we screw it up, start over. Try something else. If we wait until we've satisfied all the uncertainties, it may be too late” ~ Lee Iacocca

Related:

Get-Process - Get a list of processes on a machine
Wait-Job - Wait for a background job
Wait-Event - Wait until a particular event is raised


© Copyright SS64.com 1999-2013
Some rights reserved