Wait For a Program to Finish

by Mar 17, 2011

You should use Start-Process and its -Wait parameter if you want to force PowerShell to wait for a program to finish before it continues:

Start-Process notepad -Wait

This will cause PowerShell to suspend until you close Notepad. You should access the program with Get-Process and call its method WaitForExit() if you want to wait for programs that you did not launch yourself, or wait for a program after you launched it. The next line will wait for all running Notepad processes to exit before PowerShell continues:

Get-Process notepad | Foreach-Object { $_.WaitForExit() }

 

 

Twitter This Tip!
ReTweet this Tip!