Skip to content

Instantly share code, notes, and snippets.

@DBremen
Last active October 21, 2015 08:44
Show Gist options
  • Select an option

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

Select an option

Save DBremen/ecff01498bcea7f4b311 to your computer and use it in GitHub Desktop.
Download files using Invoke-WebRequest
function Get-FileInvokeWebRequest{
param(
[Parameter(Mandatory=$true)]
$url,
$destinationFolder="$env:USERPROFILE\Downloads",
[switch]$includeStats
)
$destination = Join-Path $destinationFolder ($url | Split-Path -Leaf)
$start = Get-Date
Invoke-WebRequest $url -OutFile $destination
$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