Skip to content
Latchkey

Invoke-WebRequest: Download Files in PowerShell CI

Invoke-WebRequest (alias iwr) downloads a file with -OutFile or queries an HTTP endpoint; in CI add -UseBasicParsing on Windows PowerShell so it never tries to use the IE engine.

For pulling an installer or release asset on a Windows runner, Invoke-WebRequest is the built-in option. A couple of flags make it fast and reliable in headless CI.

What it does

Invoke-WebRequest performs an HTTP(S) request and returns a response object (status, headers, content) or, with -OutFile, streams the body to a file. -UseBasicParsing avoids the legacy Internet Explorer DOM parser, which is absent on Server Core and headless agents.

Common usage

PowerShell
# download an installer
Invoke-WebRequest -Uri https://example.com/setup.exe \
  -OutFile setup.exe -UseBasicParsing

# call an API with auth header
$r = Invoke-WebRequest -Uri https://api.example.com/status \
  -Headers @{ Authorization = "Bearer $env:TOKEN" } -UseBasicParsing
$r.StatusCode

Options

ParameterWhat it does
-Uri <url>The request URL
-OutFile <path>Stream the response body to a file
-UseBasicParsingSkip the IE DOM parser (needed on headless/older PS)
-Headers @{...}Custom request headers
-Method <verb>GET (default), POST, etc.
-MaximumRetryCount / -RetryIntervalSecBuilt-in retry (PowerShell 6+)

In CI

On Windows PowerShell 5.1, always add -UseBasicParsing, and set [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 before HTTPS calls, since 5.1 can default to older TLS and fail the handshake. For big files, the progress bar slows the download dramatically; set $ProgressPreference = "SilentlyContinue" first.

Common errors in CI

"The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first-launch configuration is not complete" means you omitted -UseBasicParsing on Windows PowerShell. "The request was aborted: Could not create SSL/TLS secure channel" on 5.1 means TLS 1.2 was not enabled; set SecurityProtocol first. "The remote server returned an error: (404) Not Found" is a wrong URL. Downloads that crawl are usually the progress bar; suppress $ProgressPreference.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →