Invoke-WebRequest
Fetch a web page or file
Invoke-WebRequest -Uri 'https://example.com' -UseBasicParsing
- Works on
- WindowsLinuxmacOS
- PowerShell
- 5.1 and later
- Reference
- Microsoft Learn: Invoke-WebRequest
- PowerShell 5.1 curl and wget are aliases for this cmdlet, so curl flags like -O fail. Type curl.exe to run the real curl.
- PowerShell 7 -UseBasicParsing does nothing and can be left out. The curl and wget aliases are gone, so those names run the real programs.
Downloads a response. .Content is the body. .StatusCode is the status. On Windows PowerShell 5.1, add -UseBasicParsing to avoid old Internet Explorer parsing.
For JSON APIs, Invoke-RestMethod is usually nicer.
Downloads crawling along in Windows PowerShell 5.1? The progress bar is the cause. Turn it off for the session first:
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri 'https://example.com/file.zip' -OutFile .\file.zip -UseBasicParsing
Try this
(Invoke-WebRequest -Uri 'https://example.com' -UseBasicParsing).StatusCode
Coming from another shell
| Shell | What you might type |
|---|---|
| bash / zsh | curl -O https://example.com/file.zip |
| cmd.exe | curl.exe -O https://example.com/file.zip |
More in From bash and From cmd.