Powershell - Why is Using Invoke-WebRequest Much Slower Than a Browser Download?
Without switching away from Invoke-WebRequest, turning off the progress bar did it for me. I found the answer from this thread: https://github.com/PowerShell/PowerShell/issues/2138 (jasongin commented on Oct 3, 2016)
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest <params>
For my 5MB file on localhost, the download time went from 30s to 250ms.
Note that to get the progress bar back in the active shell, you need to call $ProgressPreference = 'Continue'
.
I was using
Invoke-WebRequest $video_url -OutFile $local_video_url
I changed the above to
$wc = New-Object net.webclient
$wc.Downloadfile($video_url, $local_video_url)
This restored the download speed to what I was seeing in my browsers.