Waiting in PowerShell for all child processes to finish

jaccus picture jaccus · Feb 14, 2011 · Viewed 22.6k times · Source

I want to execute multiple external scripts in PowerShell simultaneously and then wait for all of them to finish before proceeding. Currently I am using 'start-process -NoNewWindow ...' commandlet that loops through all child processes but then terminates.

I have found many ways to wait for 1 process to finish (this is obviously trivial) but none of them seem to work as a solution for my problem.

Having an equivalent for UNIX version in PowerShell would definitely be what I am looking for.

Answer

Keith Hill picture Keith Hill · Feb 14, 2011

And don't forget about probably the most straight forward way to do this for mulitple processes - Wait-Process e.g.:

$procs = $(Start-Process Notepad.exe -PassThru; Start-Process Calc.exe -PassThru)
$procs | Wait-Process