Back to blog

How to Use PowerShell Invoke-WebRequest With a Proxy in 2025

-
Table of contents
-

Key takeaways:

  • Use -Proxy and -ProxyCredential to configure your proxy server in PowerShell.
  • Store credentials in environment variables or secure vaults and avoid hardcoding.
  • Rotate proxy details with arrays or managed proxy services to reduce blocks while scraping.

Using PowerShell to gather data from websites is full of unpleasant surprises and limitations. You’ll often find yourself running into blocks, restrictions, or even complete denial of access. It’s especially true if you’re doing large-scale scraping.

Proxies, however, can help solve some of these problems and make scraping more efficient. You’ll learn how to use Invoke-WebRequest with a proxy, set up authentication, handle SSL issues, and rotate proxies efficiently.

What is Invoke-WebRequest in PowerShell?

Invoke-WebRequest is a built-in PowerShell cmdlet used for making HTTP and HTTPS requests to web pages and APIs. It can also be configured to use a proxy server. It can return the page content, status codes, headers, and more significant HTML elements like forms, links, or input fields.

Unlike Invoke-RestMethod, which automatically parses JSON responses into PowerShell objects, Invoke-WebRequest gives you more control and flexibility. It’s better suited when the goal is to scrape websites or analyze the full response body, not just work with APIs.

If you need other functionalities for your project, feel free to browse and compare alternatives to PowerShell such as cURL and Wget.

Why use a proxy with Invoke-WebRequest?

Using a proxy server gives you many benefits when you’re making web requests through PowerShell. Some of them include:

  • Anonymity. Hides your IP and keeps your identity private, also preventing your true IP address bans.
  • Geo-targeting. Helps access region-specific content by using a proxy server IP from another country.
  • IP rotations. Use different proxy details to avoid detection when scraping.
  • Bypassing rate limits. Multiple proxies split your traffic, making bans less likely, but not completely inevitable.

Rotating proxies become essential when you need to scrape large websites without interruptions or you need to do it on a daily or weekly basis to keep the data fresh.

Many developers today use proxies inside headless browsers which support proxies natively, but PowerShell with proxies can still be useful for lightweight or administrative web requests.

How to install Invoke-WebRequest

Getting to the brass tacks, let’s see how everything works in practice. Here’s an installation walkthrough for different operating systems.

Windows

If you’re using Windows 10 or 11, Invoke-WebRequest is already included, which means no installation is needed whatsoever. Open PowerShell and run:

Get-Command Invoke-WebRequest

If it doesn’t show up, update PowerShell to the latest version.

macOS

macOS typically doesn’t have PowerShell installed and you need to do it yourself. To use Invoke-WebRequest, first install PowerShell via Homebrew:

brew install powershell

Then, launch it using:

pwsh

Linux

First, install PowerShell via Snap or package manager:

sudo snap install powershell --classic

Alternatively, on Debian/Ubuntu you can install PowerShell via APT, but first register Microsoft’s repo, then run:

sudo apt-get install -y powershell

Then you can start making web requests just like you would on Windows.

Basic syntax for using a proxy

To use a proxy server in PowerShell, pass the -Proxy parameter first:

Invoke-WebRequest -Uri "https://httpbin.org/ip" -Proxy "http://IP_ADDRESS:PORT"

It points the web request to your proxy server URL.

For security reasons, you may want to store your credentials in environment variables or encrypted secrets, instead of hardcoding them:

$env:PROXY_USER = "your_actual_username"
$env:PROXY_PASS = "your_actual_password"

Then create appropriate objects by running the commands below separately:

$securePassword = ConvertTo-SecureString $env:PROXY_PASS -AsPlainText -Force
$proxyCredentials = New-Object System.Management.Automation.PSCredential($env:PROXY_USER, $securePassword)

Use PowerShell’s secure vaults when managing credentials. It keeps your proxy configuration safer.

Now you can pass proxy authentication credentials like so:

Invoke-WebRequest -Uri "https://httpbin.org/ip" `
    -Proxy "IP_ADDRESS:PORT" `
    -ProxyCredential $proxyCredentials

That’s it. Just swap in your proxy IP and credentials, and you’re good to go.

Rotating proxies for web scraping

Using only one proxy server will most likely get you blocked quickly. Instead, create a list of proxy server URLs, then randomize them:

$proxies = @(
    "http://proxy1.com:8080",
    "http://proxy2.com:8080",
    "http://proxy3.com:8080"
)

$randomProxy = Get-Random -InputObject $proxies
Invoke-WebRequest -Uri "https://httpbin.org/ip" -Proxy $randomProxy

For large scraping tasks, it’s better to use managed proxy pools like MarsProxies. These reliable proxies come with automatic rotation so you won’t have to worry about any manual rotation work.

Using HTTPS proxy and bypassing SSL issues

You can bypass invalid certificate errors in PowerShell 6+ using -SkipCertificateCheck. In Windows PowerShell 5.1, there is no built-in flag; you must import the certificate or use a .NET callback workaround.

Invoke-WebRequest -Uri "https://httpbin.org/ip" -SkipCertificateCheck

Keep in mind that using -SkipCertificateCheck disables TLS validation and is unsafe for production.

Troubleshooting common errors

Here are some of the most common PowerShell proxy errors:

  • 407 Proxy Authentication Required. That means your authentication failed and you need to check your credentials.
  • Connection timeout. The proxy server IP might be down or too slow.
  • Invalid proxy format. Make sure you include http:// or https:// and use the correct proxy settings.

Always validate your proxy configuration before launching large scraping tasks.

Best practices for secure proxy use

It’s always a good idea to keep your setup as safe as possible. Here are some guidelines:

  • Don’t hardcode your credentials or store them in plain text. Use environment variables instead.
  • Use encrypted vaults when storing secrets.
  • Limit the request rate when making HTTP(s) requests, otherwise you may get banned.
  • Review and adjust your HTTP headers (like User-Agent or Referer) to reduce detection.

You may also want to consider adding additional HTTP headers when needed to better mimic genuine browser traffic.

Keeping your PowerShell proxy configuration clean and secure is just as important as choosing the right proxy server.

Which proxy to use with PowerShell?

There are several different types of proxy servers you can choose from and they mostly differ in terms of pricing, trustworthiness, and speed:

  • Residential proxies are great for mimicking genuine user traffic as they come from regular households and networks that real people use. However, they’re more expensive.
  • Datacenter proxies are very fast but also very easy to detect as they are created in datacenters and cannot mimic genuine traffic.
  • ISP proxies are datacenter IPs leased from internet service providers, so they appear as residential but offer the speed and stability of datacenter proxies.
  • Mobile proxies are excellent for high-trust scraping and are generally considered among the most reliable types of proxies in the market.

In short, each has its own pros and cons. The one you choose will depend solely on your project’s needs and budget.

What is Invoke-WebRequest used for in PowerShell?

It sends web requests to URLs and lets you interact with the response, headers, and content.

Is the Invoke-WebRequest same as cURL?

No. cURL is a command-line tool. Invoke-WebRequest is a PowerShell cmdlet with different syntax and capabilities.

What is the difference between web request and REST API?

A web request is any request made to a web server. REST API requests are a specific type of web request designed around REST principles, often returning structured data such as JSON or XML.

What is the difference between Invoke-WebRequest and Invoke-RestMethod?

Invoke-RestMethod parses JSON responses automatically. Invoke-WebRequest gives you full control over the raw content and HTML.

Learn more
-

Related articles