On this page

Invoke-RestMethod vs. Invoke-WebRequest

Updated on June 21, 2026

Enrico Hochkoeppler Profile

By Enrico Hochkoeppler

Web Developer & TutoriaLibre Founder

Invoke-RestMethod and Invoke-WebRequest are the two primary cmdlets PowerShell provides for making HTTP and HTTPS requests. Although they share the same underlying engine and support nearly identical parameters, they serve fundamentally different purposes. Invoke-RestMethod is designed specifically for consuming REST APIs and structured data—it automatically parses JSON and XML responses into PowerShell objects, eliminating manual conversion. Invoke-WebRequest is a general-purpose HTTP client that returns the full response, including headers, status codes, cookies, and raw content, making it suitable for web scraping, file downloads, and inspecting HTTP metadata. Choosing the right cmdlet depends on whether you need structured data or complete HTTP response details.


Conceptual Difference Between the Two Cmdlets​

The key distinction lies in how each cmdlet interprets the HTTP response.

In other words:


How Invoke-RestMethod Processes Responses​

Invoke-RestMethod assumes that the endpoint returns structured data, typically JSON or XML. When it receives such data, it automatically parses it and converts it into PowerShell objects.

Example: Retrieving JSON Data​


$response = Invoke-RestMethod -Uri "https://api.example.com/v1/users"

Code explanation: The API returns JSON. PowerShell converts the JSON into objects. $response now behaves like a collection of PowerShell objects, not raw text. You can access properties directly:


$response[0].name

$response[0].email

Example: Retrieving an RSS Feed​


Invoke-RestMethod -Uri "https://devblogs.microsoft.com/powershell/feed/" |

    Format-Table -Property Title, pubDate

Code explanation: For an RSS or ATOM feed, PowerShell returns the Item or Entry XML nodes. The result is a collection of PowerShell objects that can be piped directly to other cmdlets.

Advantages of Invoke-RestMethod​

Because of these features, Invoke-RestMethod is the preferred cmdlet for most modern API integrations.


How Invoke-WebRequest Processes Responses​

Invoke-WebRequest is a lower-level HTTP client. It returns a WebResponseObject , which contains:

Example: Retrieving a Web Page​


$response = Invoke-WebRequest -Uri "https://example.com"

Code explanation: The cmdlet sends a GET request and returns a WebResponseObject. $response.Content contains the raw HTML. $response.Headers contains the HTTP headers. $response.Links contains hyperlinks extracted from the page.

To access specific properties:


$response.StatusCode        # 200

$response.StatusDescription # OK

$response.Headers           # Dictionary of HTTP headers

$response.Links             # Hyperlinks from the page

$response.Forms             # Forms from the page

Inspecting Headers and Connection Details​


$response = Invoke-WebRequest -Uri "https://devblogs.microsoft.com/powershell/"

$response.Headers

$response.BaseResponse.Server

$response.BaseResponse.IsFromCache

Code explanation: Invoke-WebRequest provides access to detailed connection information, such as the server name, whether the content was served from a cache, and all HTTP headers.

Downloading Files​


Invoke-WebRequest -Uri "https://example.com/file.zip" -OutFile "file.zip"

Code explanation: Invoke-WebRequest supports the -OutFile parameter to save the response directly to disk. In PowerShell 7.4 and later, the -Resume parameter enables interruption recovery without complete restart.

Manual JSON Parsing with Invoke-WebRequest​

Invoke-WebRequest does not automatically convert JSON into objects. If you want to parse JSON, you must do so manually:


$raw = Invoke-WebRequest -Uri "https://api.example.com/v1/users"

$data = $raw.Content | ConvertFrom-Json

$data[0].name

Choosing the Right Cmdlet​

The choice between the two cmdlets depends on your goal.

Use Invoke-RestMethod when:​

Use Invoke-WebRequest when:​


Practical Comparison​

Scenario: Calling a JSON API​

Using Invoke-RestMethod:


$response = Invoke-RestMethod -Uri "https://api.example.com/v1/users"

$response[0].name

The response is already a PowerShell object.

Using Invoke-WebRequest:


$raw = Invoke-WebRequest -Uri "https://api.example.com/v1/users"

$data = $raw.Content | ConvertFrom-Json

$data[0].name

You must manually parse the JSON.

Scenario: Downloading a File​

Invoke-RestMethod is not designed for file downloads.

Using Invoke-WebRequest:


Invoke-WebRequest -Uri "https://example.com/file.zip" -OutFile "file.zip"

This saves the file directly to disk.

Scenario: Inspecting Headers​

Using Invoke-WebRequest:


$response = Invoke-WebRequest -Uri "https://api.example.com/v1/users"

$response.Headers

Invoke-RestMethod does not expose headers unless an error occurs.

Scenario: Parsing an RSS Feed​

Both cmdlets can parse RSS feeds, but Invoke-RestMethod does so automatically:


Invoke-RestMethod -Uri "https://devblogs.microsoft.com/powershell/feed/" |

    Format-Table -Property Title, pubDate

With Invoke-WebRequest, you would need to manually parse the XML.


Error Handling Differences​

When an API returns an error:

PowerShell 7 Enhancement: -SkipHttpErrorCheck​

In PowerShell 7, both cmdlets support the -SkipHttpErrorCheck switch parameter, which suppresses exceptions at the web client level:


Invoke-RestMethod -Uri "https://example.org/NoSuchPageExists" -SkipHttpErrorCheck

Code explanation: When -SkipHttpErrorCheck is used, the cmdlet does not throw an exception on HTTP errors. Instead, it returns $null, allowing you to handle errors manually.


PowerShell 7 Improvements​

Both cmdlets have received significant improvements in PowerShell 7:

-UseBasicParsing in PowerShell 7​

In Windows PowerShell, the -UseBasicParsing parameter forces the use of a built-in parser instead of relying on Internet Explorer's parsing capabilities. Since Internet Explorer is deprecated and absent from non-Windows operating systems, you should always use this parameter in Windows PowerShell. In PowerShell 7, the -UseBasicParsing parameter has been deprecated. All web requests now use basic parsing by default. This parameter remains for backward compatibility but has no effect on the cmdlet's operation.


Summary​

Invoke-RestMethod and Invoke-WebRequest serve different but complementary purposes:

FeatureInvoke-RestMethod``Invoke-WebRequestPrimary purposeREST API consumptionGeneral HTTP clientJSON parsingAutomaticManualXML parsingAutomaticManualAccess to headersLimitedFullAccess to cookiesNoYesHTML parsingNoYesFile downloadsNoYesForm/Link extractionNoYesBest use caseStructured API dataRaw HTTP interaction

In practice:

Mastering both cmdlets gives you the flexibility to interact with modern APIs, traditional web services, and raw HTTP endpoints in a consistent and reliable way.

Found this helpful? Share the knowledge...

... or support this project to keep it alive!

Buy Me a Coffee

Previous

Rest APIs

Next

Parsing JSON and XML