Waits for a set of PowerShell jobs to complete, receives each job as it finishes, and returns the number of jobs that didn't complete successfully.
Complete-Job [-Job] <Job[]> [[-IntervalSeconds] <Int32>] [<CommonParameters>]
Job management in PowerShell is a pain. At a minimum, you have to wait for each job to complete, then receive its output. This function manages all that for you. It iterates over a list/array of jobs, as each job finishes, it receives its output and removes it. If a job is blocked or stopped it receives and removes those jobs. When its all done, it returns the number of jobs that failed, were blocked, or stopped.
By default, it sleeps for one second between status checks. You can increase this interval using the IntervalSeconds
parameter.
This function never times out.
Name | Type | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
Job | Job[] | true | false | ||
IntervalSeconds | Int32 | The number of seconds to sleep between job status checks. Default is 1 second. | false | false |
Complete-Job -Job $jobs
Sits and waits for all the jobs in $jobs
to finish, block, or stop and returns the number that didn't succeed. It waits one second between status checks.
Complete-Job -Job $jobs -IntervalSeconds 60
Waits for all the jobs in $jobs
to finish, waiting 60 seconds between status checks.