The Wait-Job command

The Wait-Job command waits for all of the jobs in the input pipeline to complete. Wait-Job supports a degree of filtering and offers a timeout to define jobs to wait for.

In some cases, it is desirable to pull off output from jobs as they complete. This can be solved by creating a while or do loop in PowerShell, reacting to jobs as the state changes:

while (Get-Job -State Running) {    $jobs = Get-Job -State Completed    $jobs | Receive-Job    $jobs | Remove-Job    Start-Sleep -Seconds 1}

A while loop does not have an output pipeline, if output is to be piped to another command it would need to be piped within the loop. For example, if the job output were filling a CSV file, Export-Csv would be added inside the loop and the Append ...

Get Mastering Windows PowerShell Scripting - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.