Windows: PowerShell – Download File From URL

Windows PowerShell can be used for downloading files via HTTP and HTTPS protocols.

In PowerShell, as an alternative to the Linux curl and wget commands, there is an Invoke-WebRequest command, that can be used for downloading files from URLs.

In this note i am showing how to download a file from URL using the Invoke-WebRequest command in PowerShell, how to fix slow download speed and how to pass HTTP headers (e.g. API key)

Wget & cURL: The curl and wget commands in PowerShell are the aliases of the Invoke-WebRequest command.

Download File Using PowerShell

Download a file from URL using PowerShell via HTTP and HTTPS protocols:

PS C:\> Invoke-WebRequest https://path/to/file.txt -OutFile C:\file.txt

Download a large file (hide the progress of the Invoke-WebRequest command, as it extremely slows down the download speed):

PS C:\> $progresspreference = 'silentlyContinue'
PS C:\> Invoke-WebRequest https://path/to/file.txt -OutFile C:\file.txt
PS C:\> $progressPreference = 'Continue'

Download a file passing header values (e.g. pass API key):

PS C:\> Invoke-WebRequest -H @{'apiKey'='keyValue'} https://path/to/file.txt -OutFile C:\file.txt

Download a file passing multiple header values:

PS C:\> Invoke-WebRequest -H @{'authUser'='userValue'; 'authPass'='passValue'} https://path/to/file.txt -OutFile C:\file.txt