Created
March 18, 2014 01:57
-
-
Save ciphertxt/9612181 to your computer and use it in GitHub Desktop.
Progress bar for current "Transferring" BITS Transfers with a time remain calculation.
This file contains hidden or 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
| 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 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Made some formatting changes, if you're interested - https://gist.github.com/n-engelhardt/ca6157c0a8409ac94a42cdbafebb8278