PowerShell 2.0: One Cmdlet at a Time 101 Wait-Process

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Wait-Process cmdlet.

What can I do with it?

Wait for a process to stop before proceeding further.


Open an instance of Notepad. Use Wait-Process to pause the console session until Notepad is closed.

Notepad Wait-Process -Name Notepad

You will notice that the console pauses whilst Notepad is open

Once Notepad is closed, control of the session is returned to the user.

How could I have done this in PowerShell 1.0?

Store the result of Get-Process Notepad in a variable, then use the WaitForExit method to wait for the process to stop.

Notepad $Process = Get-Process Notepad $Process.WaitForExit()

1000 things 1% better