Skip to content

Instantly share code, notes, and snippets.

@DBremen
Last active October 27, 2015 12:58
Show Gist options
  • Select an option

  • Save DBremen/e14cbf8c336a074048ab to your computer and use it in GitHub Desktop.

Select an option

Save DBremen/e14cbf8c336a074048ab to your computer and use it in GitHub Desktop.
Download files using Start-BitsTransfer in synchronous mode
function Get-FileBitsTransferSynchronous{
param(
[Parameter(Mandatory=$true)]
$url,
$destinationFolder="$env:USERPROFILE\Downloads",
[switch]$includeStats
)
Import-Module BitsTransfer
$destination = Join-Path $destinationFolder ($url | Split-Path -Leaf)
$start = Get-Date
Start-BitsTransfer -Source $url -Destination $target
$elapsed = ((Get-Date) - $start).ToString('hh\:mm\:ss')
$totalSize = (Get-Item $destination).Length | Get-FileSize
if ($includeStats.IsPresent){
[PSCustomObject]@{Name=$MyInvocation.MyCommand;TotalSize=$totalSize;Time=$elapsed}
}
Get-Item $destination | Unblock-File
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment