Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import-module poshrsjob;
$PollingInterval = 5;
$CompletedThreads = 0;
$Status = Get-RSJob | Group-Object -Property State;
$TotalThreads = ($Status|Select-Object -ExpandProperty Count | Measure-Object -Sum).Sum;
while ($CompletedThreads -lt $TotalThreads) {
$CurrentJobs = Get-RSJob;
$CurrentJobs.Where( {$PSItem.State -eq "Completed"}) | Receive-RSJob | Out-Null;
$CurrentJobs.Where( {$PSItem.State -eq "Completed"}) | Remove-RSJob | Out-Null;
$Status = $CurrentJobs|Group-Object -Property State;
$CompletedThreads += $Status | Where-Object {$PSItem.Name -eq "Completed"} | Select-Object -ExpandProperty Count;
$PctComplete = ($CompletedThreads / $TotalThreads) * 100;
Write-Progress -Activity "Downloading Files" -Status "Completed $CompletedThreads of $TotalThreads ($PctComplete)%" -Id 1 -PercentComplete $PctComplete;
start-sleep -seconds $PollingInterval;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment