Friday, 27 September 2013

PowerShell v2.0 equivalent to "get-job | receive-job -AutoRemoveJob -Wait"?

PowerShell v2.0 equivalent to "get-job | receive-job -AutoRemoveJob -Wait"?

What is the PowerShell v2.0 equivalent to this v3.0 code snippt:
for($i=0; $i -lt $num_jobs; $i++) {
Write-Host -ForegroundColor Darkgreen "[i] Job" $i "starting..."
Start-Job -ScriptBlock $insert_data -ArgumentList 'host', 'user',
'pass', 'db', $i, $log_out[$i] | Out-Null;
}
get-job | receive-job -AutoRemoveJob -Wait
I tried the following without luck
for($i=0; $i -lt $num_jobs; $i++) {
Write-Host -ForegroundColor Darkgreen "[i] Job" $i "starting..."
Start-Job -ScriptBlock $insert_data -ArgumentList 'host', 'user',
'pass', 'db', $i, $log_out[$i] | Out-Null;
}
get-job | receive-job -Wait
get-job | remove-job
It fails on PowerShell v2.0 with:
Remove-Job : The command cannot remove the job with the 3 session
identifier be
cause the job is not finished. To remove the job, first stop the job, or
use th
e Force parameter.

No comments:

Post a Comment