Download Files With PowerShell
By: Cam Wohlfeil
Published: 2018-02-07 0000 EST
Category: Solutions
Tags:
powershell
This blog post on the topic is phenomenal, but I'll briefly summarize it. Theres three method to download a file with PowerShell: Invoke-WebRequest, System.Net.WebClient, and Start-BitsTransfer. All have pros and cons; Invoke-WebRequest is built-in and very simple but requires Internet Explorer and is very slow, System.Net.WebClient works everywhere and is very fast but is much more complicated, and Start-BitsTransfer is the best of both worlds but if another BITS transfer (like Windows update) is going on it may cause your download to be queued. After learning this, I'll stick to BITS unless I run in to issues.
# Required for BitsTransfer
Import-Module BitsTransfer
# Can be done inline instead
$url = "http://mirror.internode.on.net/pub/test/10meg.test"
$output = "$PSScriptRoot\10meg.test"
# Method 1
Invoke-WebRequest -Uri $url -OutFile $output
# Method 2
(New-Object System.Net.WebClient).DownloadFile($url, $output)
# Method 3
Start-BitsTransfer -Source $url -Destination $output
More Info: