Wandering Journey

Jounaling the travel from one subject to another, often with no definite destination or purpose...

PowerShell: Invoke-WebRequest

22 January 2021

Why does it take five minutes to download a file 95MB file using Invoke-WebReqeust?

PS C:\Users\WDAGUtilityAccount> $progressPreference = 'Continue'
PS C:\Users\WDAGUtilityAccount> measure-command { invoke-webrequest "https://github.com/PowerShell/PowerShell/releases/download/v7.1.1/PowerShell-7.1.1-win-x64.msi" -Outfile $($DownloadPath + "PowerShell-7.1.1-win-x64.msi") -ErrorAction Stop  }


Days              : 0
Hours             : 0
Minutes           : 5
Seconds           : 1
Milliseconds      : 210
Ticks             : 3012107201
TotalDays         : 0.00348623518634259
TotalHours        : 0.0836696444722222
TotalMinutes      : 5.02017866833333
TotalSeconds      : 301.2107201
TotalMilliseconds : 301210.7201



PS C:\Users\WDAGUtilityAccount>

I found the answer in turning off the on-screen progress reporting. Changing the $progressPreference reduced the 95MB download from 5 minutes to 12 seconds.

PS C:\Users\WDAGUtilityAccount> $progressPreference = 'silentlyContinue'
PS C:\Users\WDAGUtilityAccount> measure-command { invoke-webrequest "https://github.com/PowerShell/PowerShell/releases/download/v7.1.1/PowerShell-7.1.1-win-x64.msi" -Outfile $($DownloadPath + "PowerShell-7.1.1-win-x64.msi") -ErrorAction Stop  }


Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 12
Milliseconds      : 298
Ticks             : 122987048
TotalDays         : 0.00014234612037037
TotalHours        : 0.00341630688888889
TotalMinutes      : 0.204978413333333
TotalSeconds      : 12.2987048
TotalMilliseconds : 12298.7048



PS C:\Users\WDAGUtilityAccount> $progressPreference = 'Continue'