Invoke-WebRequest
noun
say it: “in-VOHK web-ri-KWEST” /ɪnˈvoʊk ˈwɛb rɪˈkwɛst/
A PowerShell command that asks a web address and gives back the whole answer: its status code, its headers and its content.
What does Invoke-WebRequest do?
Invoke-WebRequest asks a web address and hands back the whole answer: the StatusCode (such as 200 for OK or 404 for not found), the Headers and the Content. Use it to check whether a site is up, read a header or download a file with -OutFile; for an API's data as objects, Invoke-RestMethod is shorter. An error code stops it, unless you add -SkipHttpErrorCheck.
(Invoke-WebRequest 'https://example.com').StatusCode
Invoke-WebRequest 'https://api.weather.gov/gridpoints/LOT/76,73/forecast' -OutFile forecast.json
In a sentence
- “Sam saved the forecast to a file with Invoke-WebRequest -OutFile forecast.json.”
- “Invoke-WebRequest showed a StatusCode of 200, so the bakery's site was up.”
Level: Journeyman · More PowerShell terms at this level
Updated