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
}