Skip to content

Instantly share code, notes, and snippets.

@alevyinroc
Created December 14, 2018 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alevyinroc/98e4b2f2ab105b885f4d3cd64fae2598 to your computer and use it in GitHub Desktop.
Save alevyinroc/98e4b2f2ab105b885f4d3cd64fae2598 to your computer and use it in GitHub Desktop.
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