---
title: "PowerShell Invoke-WebRequest: A Comprehensive Guide"
description: "Learn how to use the PowerShell Invoke-WebRequest cmdlet to send any HTTP verb to a web service, along with common tasks like handling HTTP parameters."
canonical: "https://adamtheautomator.com/invoke-webrequest/"
---

# PowerShell Invoke-WebRequest: A Comprehensive Guide

> Learn how to use the PowerShell Invoke-WebRequest cmdlet to send any HTTP verb to a web service, along with common tasks like handling HTTP parameters.

Source: https://adamtheautomator.com/invoke-webrequest/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![PowerShell Invoke-WebRequest: A Comprehensive Guide](https://adamtheautomator.com/wp-content/uploads/2019/06/5d238ae5c824b514689ea524.jpg)

# PowerShell Invoke-WebRequest: A Comprehensive Guide

[![](https://secure.gravatar.com/avatar/d0b9d42e21e5622713f8b693aa5c0f9244d5f7dd200ed29b8398f52dee5de337?s=192&d=mm&r=g)Adam Bertram](https://adamtheautomator.com/author/adam-bertram/)16 June 20193 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PowerShell](/tag/powershell/)

Table of Contents

*   [Basic Usage](#basic-usage)
*   [Downloading Files with Invoke-WebRequest](#downloading-files-with-invoke-webrequest)
*   [Submitting a Form and Working with Sessions](#submitting-a-form-and-working-with-sessions)
*   [Resolving Short URIs](#resolving-short-uris)
*   [Summary](#summary)

Have you ever wanted to browse the web via the command line? Yea. Me neither. But have you ever needed to pull information from a webpage, monitor a website or submit information via automation? I have and I use Invoke-Webrequest to do it!

The `Invoke-WebRequest` PowerShell cmdlet is the swiss army knife for the web. This cmdlet can send any HTTP verb to a web service along with common things like HTTP parameters, specify different HTTP headers and so on. `Invoke-WebRequest` along with it’s brother, `Invite-RestMethod` are the two PowerShell cmdlets you’ll want to familiarize yourself with if you need to do any kind of web automation.

The `Invoke-WebRequest` cmdlet is a part of the _Microsoft.PowerShell.Utility_ module that comes with Windows PowerShell and PowerShell Core. This cmdlet was included with PowerShell ever since v3 and it’s one that is extremely powerful yet easy to use.

By using `Invoke-WebRequest`, [PowerShell](https://adamtheautomator.com/tag/powershell/) allows a developer to work with websites, web services and REST APIs in a lot of different ways.

## Basic Usage

At it’s most basic, the `Invoke-WebRequest` cmdlet sends an HTTP request method to an endpoint such as a URI or URL. The cmdlet supports all of the common [request methods](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods).

By far, the most common method is the _GET_ method. This method reads information such as information from a website or maybe querying a REST API. The method is defined by using the `Method` parameter. Since we need an endpoint to query, we’ll also need a URI as well. To keep this easy, I’ll pick any website. To shamelessly promote TechSnips, I’ll choose techsnips.io.

Let’s say I want to get a listing of all of the latest published videos as shown below.

![Example webpage](https://adamtheautomator.com/content/images/2019/07/invoke-webrequest-powershell---invoke-webrequest1.png)

Example webpage

I can get an HTML representation of this page by running `Invoke-WebRequest -Uri 'https://techsnips.io' -Method GET`. When I do this, `Invoke-WebRequest` downloads the entire web page and returns an output with various parsed information around the elements of the page.

![Invoke-WebRequest response](https://adamtheautomator.com/content/images/2019/07/invoke-webrequest-powershell---invoke-webrequest2.png)

Invoke-WebRequest response

To get the videos, I’ll need to do some digging. When I look at the links property I see a commonality that all of the video links have a class of `ng-binding` as shown below.

![Parsing Invoke-WebRequest output](https://adamtheautomator.com/content/images/2019/07/invoke-webrequest-powershell---invoke-webrequest3.png)

$result.Links | where {$\_.class -eq ‘ng-binding’}

Once I know this, I can then find all of those elements and only return the `innerHTML` property and voila!

![The final web result](https://adamtheautomator.com/content/images/2019/07/invoke-webrequest-powershell---invoke-webrequest4.png)

$result.links | where {$\_.class -eq ‘ng-binding’} | Select-Object innerHtml

## Downloading Files with Invoke-WebRequest

We can also use `Invoke-WebRequest` to download files from the web as well and it’s really easy! We can download files by simply pointing `Invoke-WebRequest` at a URI of a file and using the `OutFile` parameter to tell the cmdlet to save the file to local disk.

As an example, below I’m downloading the SysInternals Handle utility and expanding the zip file once downloaded. It’s really that easy!

```powershell
Invoke-WebRequest -Uri 'https://download.sysinternals.com/files/Handle.zip' -OutFile C:\handle.zi Expand-Archive -Path C:\handle.zip
```

## Submitting a Form and Working with Sessions

We can use `Invoke-WebRequest` to also fill forms. To do this though, we commonly need to work with web sessions. HTTP is a naturally stateless protocol and your browser (in this case PowerShell) must be able to create a session which will be used to track things like cookies, for example. A common form is a login/password form so let’s login to a fictional website!

Let’s say our fictional login form is at the URL _http://somewebsite.com_. We’d first need to run `Invoke-WebRequest` to download the HTML structure and create a session.

```powershell
$response = Invoke-WebRequest -Uri 'http://somewebsite.com' -SessionVariable rb
```

Once we do this, the response will have a `Forms` property we can then populate with a username and password. In this case, the username is represented by a field called `user` and the password should be in a field called `password`. This will depend on the webpage.

```powershell
$form = $response.Forms[0]
$form.Fields["user"] = "username"
$form.Fields["password"] = "password"
```

Once the form has been populated, we can then use `Invoke-WebRequest` again but this time re-use the session we just created and automatically figure out the URI to send it to by reading the `Action` property that’s on the form as shown below.

```powershell
$response = Invoke-WebRequest -Uri $form.Action -WebSession $rb -Method POST
```

If you’ve got all of the appropriate field names right and the webpage isn’t doing any fancy, you should be logged in with the username and password inside of the `$rb` web session. At this point, you can read various pages behind that authentication if you use the `$rb` web session variable.

## Resolving Short URIs

Finally, another great use of `Invoke-WebRequest` is resolving short URIs. Perhaps you need to know what’s behind that shortened URL but don’t want to click on it to find out! No problem. Using `Invoke-WebRequest`, we can read the `AbsoluteUri` property from the parsed response it gives us!

Notice below I’m also using the `UseBasicParsing` parameter. By default, `Invoke-WebRequest` tries to use Internet Explorer (IE) to parse the HTML returned. This doesn’t work on systems without IE. To get around that, we can use the `UseBasicParsing` parameter to still download the content but only lightly parse it.

```powershell
$Url = 'buff.ly/2sWvPOH'
$Web = Invoke-WebRequest -Uri $Url -UseBasicParsing
$Web.BaseResponse.ResponseUri.AbsoluteUri
```

## Summary

The `Invoke-WebRequest` cmdlet is one of the most versatile cmdlets that come with PowerShell. If there’s an action that can be performed via a typical graphical browser, the `Invoke-WebRequest` cmdlet can do it too. You can find an example of using this cmdlet by taking a look at this article on [monitoring REST APIs](https://adamtheautomator.com/powershell-json/).

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Finvoke-webrequest%2F&text=PowerShell%20Invoke-WebRequest%3A%20A%20Comprehensive%20Guide)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Finvoke-webrequest%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Finvoke-webrequest%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/06/26995-troubleshoot-dns-issues-powershell-codex.webp)

### [Troubleshoot DNS Issues with PowerShell](/troubleshoot-dns-issues-powershell/)

Troubleshoot DNS issues with PowerShell by testing name resolution, DNS client settings, cache entries, and network connectivity in a repeatable workflow.

![](https://adamtheautomator.com/wp-content/uploads/2025/10/image_2025-10-24_095322075.png)

### [Migrating from PowerShell 6 to 7.5: Breaking Changes/New Features](/migrating-powershell-6-to-7-5/)

Migrate from PowerShell Core 6 to 7.5: breaking changes, features, and testing tips.

![](https://adamtheautomator.com/wp-content/uploads/2025/06/featured-image-6.png)

### [How to Add Timeouts to Pester Tests with PowerShell Runspaces](/pester-test-timeout-runspaces/)

Prevent Pester tests from hanging indefinitely using PowerShell runspaces. Learn to handle variable scoping, module loading, TestDrive access, and stream capture challenges with timeout protection.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
