Last active
October 12, 2015 01:15
-
-
Save martin9700/e4970e7e8a0ce131271d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Num = 5 | |
$Jobs = @() | |
ForEach ($Job in (1..$Num)) | |
{ $Jobs += Start-Job -ScriptBlock { | |
$Count = 1 | |
Do { | |
Write-Progress -Id 2 -Activity "Background Job" -Status $Count -PercentComplete 1 | |
$Count ++ | |
Start-Sleep -Seconds 4 | |
} Until ($Count -gt 5) | |
} | |
} | |
$Total = $Num * 5 | |
Write-Progress -Id 1 -Activity "Watching Background Jobs" -Status "Waiting for background jobs to started" -PercentComplete 0 | |
Do { | |
$TotProg = 0 | |
ForEach ($Job in $Jobs) | |
{ Try { | |
$Info = | |
$TotProg += ($Job | Get-Job).ChildJobs[0].Progress.StatusDescription[-1] | |
} | |
Catch { | |
Start-Sleep -Seconds 3 | |
Continue | |
} | |
} | |
If ($TotProg) | |
{ Write-Progress -Id 1 -Activity "Watching Background Jobs" -Status "Waiting for background jobs to complete: $TotProg of $Total" -PercentComplete (($TotProg / $Total) * 100) | |
} | |
Start-Sleep -Seconds 3 | |
} Until (($Jobs | Where State -eq "Running").Count -eq 0) | |
$Jobs | Remove-Job -Force | |
Write-Progress -Id 1 -Activity "Watching Background Jobs" -Status "Completed! $Total of $Total" -PercentComplete 100 | |
Start-Sleep -Seconds 1 | |
Write-Progress -Id 1 -Activity "Watching Background Jobs" -Status "Completed! $Total of $Total" -Completed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment