Skip to content

Instantly share code, notes, and snippets.

@tabs-not-spaces
Last active September 11, 2022 04:54
Show Gist options
  • Save tabs-not-spaces/0f4fa9c2f814c585eb3a2cab1b54f1bf to your computer and use it in GitHub Desktop.
Save tabs-not-spaces/0f4fa9c2f814c585eb3a2cab1b54f1bf to your computer and use it in GitHub Desktop.
function Watch-BitsTransfer {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[guid]$JobId
)
$perc = 0
while ($perc -le 100 ) {
$jobState = Get-BitsTransfer -JobId $JobId | Select-Object BytesTransferred, BytesTotal
$percentCompleteState = ($jobState.BytesTransferred / $jobState.BytesTotal * 100)
$progressParams = @{
Activity = "Downloading file"
PercentComplete = $percentCompleteState
Status = "$("{0:n2}" -f $($jobState.BytesTransferred / 1gb)) / $("{0:n2}" -f $($jobState.BytesTotal / 1gb)) : %$("{0:n2}" -f $percentCompleteState)"
}
Write-Progress @progressParams
Start-Sleep -Seconds 5
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment