Skip to content

Instantly share code, notes, and snippets.

@ciphertxt
Created March 18, 2014 01:57
Show Gist options
  • Select an option

  • Save ciphertxt/9612181 to your computer and use it in GitHub Desktop.

Select an option

Save ciphertxt/9612181 to your computer and use it in GitHub Desktop.
Progress bar for current "Transferring" BITS Transfers with a time remain calculation.
while ((Get-BitsTransfer | ? { $_.JobState -eq "Transferring" }).Count -gt 0) {
$totalbytes=0;
$bytestransferred=0;
$timeTaken = 0;
foreach ($job in (Get-BitsTransfer | ? { $_.JobState -eq "Transferring" } | Sort-Object CreationTime)) {
$totalbytes += $job.BytesTotal;
$bytestransferred += $job.bytestransferred
if ($timeTaken -eq 0) {
#Get the time of the oldest transfer aka the one that started first
$timeTaken = ((Get-Date) - $job.CreationTime).TotalMinutes
}
}
#TimeRemaining = (TotalFileSize - BytesDownloaded) * TimeElapsed/BytesDownloaded
if ($totalbytes -gt 0) {
[int]$timeLeft = ($totalBytes - $bytestransferred) * ($timeTaken / $bytestransferred)
[int]$pctComplete = $(($bytestransferred*100)/$totalbytes);
Write-Progress -Status "Transferring $bytestransferred of $totalbytes ($pctComplete%). $timeLeft minutes remaining." -Activity "Dowloading files" -PercentComplete $pctComplete
}
}
@n-engelhardt
Copy link

Made some formatting changes, if you're interested - https://gist.github.com/n-engelhardt/ca6157c0a8409ac94a42cdbafebb8278

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment