Last active
February 8, 2017 16:23
-
-
Save heiswayi/5742f47362ebbb2d5cc35f6a1eb4fc36 to your computer and use it in GitHub Desktop.
Update progress in PowerShell
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 |
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
for ($a=1; $a -lt 100; $a++) { | |
Write-Progress -Activity "Working..." -Status "Please wait" -PercentComplete $a -CurrentOperation "$a% complete" | |
Start-Sleep 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment