Integrations menu
Developer guide

PowerShell Proxy Setup: Step by Step

To use a proxy in PowerShell, add -Proxy "http://gate.proxyfield.io:7000" and -ProxyCredential $cred to Invoke-WebRequest or Invoke-RestMethod, where $cred holds your proxy username and password; to cover a whole session, set the proxy once with $PSDefaultParameterValues or [System.Net.Http.HttpClient]::DefaultProxy. ProxyField residential proxies for PowerShell cost from $1.95/GB ($2.95/GB for 1 GB), with a 99.6% success rate, according to our service data. Start with the Easy Trial: 1 GB for $2.95, no subscription, and the traffic never expires.

residential IPs
412M+
from, traffic never expires
$1.95/GB
Easy Trial
1 GB for $2.95
gate.proxyfield.io:7000
What PowerShell needs
Parameter or settingProxyField value
-Proxyhttp://gate.proxyfield.io:7000, also for https:// sites; HTTP, HTTPS and SOCKS5 all run on the same host and port
-ProxyCredentiala credential with your ProxyField username and password; a login written into -Proxy is not sent
Username<login>-country-us-city-new_york; the optional keys are -country-<cc>, -region-<region>, -city-<city>, -session-<id> and -ttl-<seconds> (30 to 129,600 s, 20 min when ttl is left out); add -mobile or -dc right after the login for mobile or rotating datacenter IPs (-dc takes the country only)
Passwordyour ProxyField password, read from an environment variable or a secret store
SOCKS5 (PowerShell 7)-Proxy "socks5://gate.proxyfield.io:7000" with the same credential; for curl.exe and other tools that take a proxy URL, write socks5h:// so the gateway resolves the site's name
Whole session$PSDefaultParameterValues or [System.Net.Http.HttpClient]::DefaultProxy in PowerShell 7; [System.Net.WebRequest]::DefaultWebProxy in Windows PowerShell 5.1
No passwordadd your public IP to the allowlist (up to 100 IPv4 addresses), leave out -ProxyCredential and use the port you set up in the dashboard in -Proxy
IP behavioura new IP on every request, or one IP for 30 s to 36 h with -session-<id>-ttl-<seconds>
Parallel requestsunlimited concurrent threads, so ForEach-Object -Parallel can send many requests at once
Headersthe gateway adds no Via, X-Forwarded-For or Forwarded header; the headers PowerShell sends pass through; your Proxy-Authorization is removed before the request goes to the site

Set up PowerShell with ProxyField

  1. Put the password in an environment variable or a secret store, not in the script.
  2. Build a credential from your ProxyField username and the password.
  3. Pass -Proxy "http://gate.proxyfield.io:7000" and -ProxyCredential $cred to Invoke-WebRequest or Invoke-RestMethod.
  4. Run Invoke-RestMethod https://api.ipify.org through the proxy: it prints the proxy's IP, not yours.

The same request in PowerShell, with the password read from $env:PROXY_PASS.

PowerShell
$cred = [pscredential]::new("<login>-country-us-city-new_york", (ConvertTo-SecureString $env:PROXY_PASS -AsPlainText -Force))
Invoke-RestMethod -Uri "https://api.ipify.org" -Proxy "http://gate.proxyfield.io:7000" -ProxyCredential $cred

Microsoft's reference for the cmdlet's proxy parameters: Invoke-WebRequest (Microsoft Learn).

Mobile 5G/4G proxies cost $3.45/GB for 1 GB down to $2.45/GB from 1,000 GB, on the same gateway and the same balance.

Your credentials, the IP allowlist and the configurator (it generates as many proxy lines as you need) are in your ProxyField account. Targeting covers country, region (state) and city, all 50 US states. Other location keys: -region-<region>, -session-<id> and -ttl-<seconds> (30 to 129,600 seconds, 20 minutes by default) after the location, as in <login>-country-us-region-new_york-city-new_york-session-he9f2qga-ttl-600. Residential or mobile: residential by default; add -mobile after the login for mobile IPs, as in <login>-mobile-country-us

On this page 13 sections

Use a proxy with Invoke-WebRequest and Invoke-RestMethod

Both web cmdlets take the same three proxy parameters, so one pattern covers HTML pages and JSON APIs:

  1. Put the password in an environment variable or a secret store, not in the script.
  2. Build a credential from your ProxyField username and password.
  3. Pass the gateway to -Proxy and the credential to -ProxyCredential.
PowerShell
$env:PROXY_USER = "<login>-country-us-city-new_york"   # location goes in the username
$env:PROXY_PASS = "<password>"                     # better: set it outside the script
$pass = ConvertTo-SecureString $env:PROXY_PASS -AsPlainText -Force
$cred = [pscredential]::new($env:PROXY_USER, $pass)

Invoke-RestMethod -Uri "https://api.ipify.org" -Proxy "http://gate.proxyfield.io:7000" -ProxyCredential $cred
$page = Invoke-WebRequest -Uri "https://example.com" -Proxy "http://gate.proxyfield.io:7000" -ProxyCredential $cred
$page.StatusCode

The first command prints the exit IP, which should not be yours. Keep the scheme http:// in -Proxy even when the site is https://: PowerShell opens an encrypted tunnel through the gateway, and the site's TLS runs inside it.

Don't put the login into the proxy address: with -Proxy "http://<login>:<password>@gate.proxyfield.io:7000", PowerShell sends no credentials at all, and the proxy answers 407 (Proxy Authentication Required); only -ProxyCredential carries them. On a machine whose public IP is on your ProxyField allowlist, drop -ProxyCredential and use the port you set up in the dashboard instead of 7000 in -Proxy.

-ProxyUseDefaultCredentials sends your Windows sign-in to the proxy. It is meant for company proxies that check Windows accounts, not for a ProxyField username and password.

Set the proxy once for a whole session

Typing -Proxy on every call gets old in a long script. PowerShell 7 gives you three ways to set it once, each for both cmdlets and for http:// and https:// sites.

Default parameter values apply only to the cmdlets you name:

PowerShell
$PSDefaultParameterValues["Invoke-WebRequest:Proxy"] = "http://gate.proxyfield.io:7000"
$PSDefaultParameterValues["Invoke-WebRequest:ProxyCredential"] = $cred
$PSDefaultParameterValues["Invoke-RestMethod:Proxy"] = "http://gate.proxyfield.io:7000"
$PSDefaultParameterValues["Invoke-RestMethod:ProxyCredential"] = $cred

The .NET default proxy covers everything in the session that uses .NET's HttpClient, including Install-PSResource:

PowerShell
$proxy = [System.Net.WebProxy]::new("http://gate.proxyfield.io:7000")
$proxy.Credentials = $cred.GetNetworkCredential()
[System.Net.Http.HttpClient]::DefaultProxy = $proxy

Environment variables are read by PowerShell 7 and by the programs it starts, such as curl.exe, Python and Git:

PowerShell
$env:HTTP_PROXY  = "http://<login>-country-us-city-new_york:<password>@gate.proxyfield.io:7000"
$env:HTTPS_PROXY = $env:HTTP_PROXY

Set them before the first web request of the session. .NET reads the variables once, at the first request, so variables set after a request in the same session are ignored until you open a new PowerShell window. Unlike -Proxy, the variables do carry the login inside the URL. To keep any of these settings in new windows, put the lines in your profile (notepad $PROFILE), with the password read from a secret store rather than written in the file. -NoProxy sends a single request directly when a session-wide proxy is set.

More on the variables themselves, and on set and setx in Command Prompt, is in command line proxy settings.

Set a proxy in Windows PowerShell 5.1

Windows PowerShell 5.1, the version built into Windows 10 and 11, takes the same -Proxy and -ProxyCredential parameters on Invoke-WebRequest and Invoke-RestMethod. What differs is the session-wide default: 5.1 is built on the .NET Framework, so you set [System.Net.WebRequest]::DefaultWebProxy instead of the HttpClient property:

PowerShell
$proxy = New-Object System.Net.WebProxy("http://gate.proxyfield.io:7000", $true)
$proxy.Credentials = New-Object System.Net.NetworkCredential("<login>-country-us-city-new_york", $env:PROXY_PASS)
[System.Net.WebRequest]::DefaultWebProxy = $proxy
Invoke-RestMethod "https://api.ipify.org"

The $true keeps local addresses off the proxy. This line does nothing in PowerShell 7, which ignores DefaultWebProxy and connects directly. Two more 5.1 habits to know: curl there is an alias of Invoke-WebRequest, so type curl.exe for real curl, and 5.1 has no SOCKS5 option in its web cmdlets.

Set the Windows system proxy from PowerShell

The proxy in Settings → Network & internet → Proxy lives in the registry for each user, so PowerShell can read and change it without the Settings window:

PowerShell
$key = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Get-ItemProperty -Path $key | Select-Object ProxyEnable, ProxyServer, ProxyOverride   # what is set now
Set-ItemProperty -Path $key -Name ProxyServer -Value "gate.proxyfield.io:7000"
Set-ItemProperty -Path $key -Name ProxyOverride -Value "localhost;127.0.0.1;<local>"
Set-ItemProperty -Path $key -Name ProxyEnable -Value 1 -Type DWord
# turn it off again
Set-ItemProperty -Path $key -Name ProxyEnable -Value 0 -Type DWord

Browsers and apps that use the Windows proxy pick up the change when they restart. The system proxy has no username or password field: with gate.proxyfield.io:7000, let the browser ask for the login; or add your PC's public IP to the allowlist in your ProxyField account and set ProxyServer to gate.proxyfield.io with the port you set up in the dashboard. Windows services such as Windows Update use a second proxy, WinHTTP, set with netsh in an elevated PowerShell window:

PowerShell
netsh winhttp set proxy proxy-server="gate.proxyfield.io:7000" bypass-list="<local>"
netsh winhttp import proxy source=ie      # or copy the user's proxy from Settings
netsh winhttp show proxy
netsh winhttp reset proxy                 # back to a direct connection

PowerShell 7 on Windows follows the user's system proxy when no proxy variable is set (Microsoft Learn: HttpClient.DefaultProxy), and Windows PowerShell 5.1 does the same through the .NET Framework. Neither reads the WinHTTP proxy. The Settings steps, with screenshots, are on Windows proxy setup.

Use a SOCKS5 proxy in PowerShell 7

PowerShell 7 runs on a .NET that speaks SOCKS5, so the web cmdlets take a socks5:// address:

PowerShell
Invoke-RestMethod -Uri "https://api.ipify.org" -Proxy "socks5://gate.proxyfield.io:7000" -ProxyCredential $cred

PowerShell 7 sends the credential with the SOCKS5 username and password method and passes the site's hostname to the proxy unresolved, so the DNS lookup happens at the proxy's end. As with HTTP, a login written into the socks5:// address is not used: PowerShell then fails with "SOCKS server did not return a suitable authentication method". For a whole session, set $env:ALL_PROXY = "socks5://<login>:<password>@gate.proxyfield.io:7000". SOCKS5 port: the same gate.proxyfield.io:7000 as HTTP and HTTPS. SOCKS5 login: yes, with the same username and password as HTTP.

Windows PowerShell 5.1 can't use SOCKS5 in its web cmdlets; run curl.exe --socks5-hostname gate.proxyfield.io:7000 -U "<login>:<password>" https://api.ipify.org instead, or install PowerShell 7 next to it. When SOCKS5 is worth it over HTTP is covered on SOCKS5 proxies.

Use curl with a proxy in PowerShell

Windows 10 and 11 include curl.exe. Call it with .exe, and it takes curl's own proxy options:

PowerShell
curl.exe -x http://gate.proxyfield.io:7000 -U "<login>-country-us-city-new_york:<password>" https://api.ipify.org

It also reads $env:HTTPS_PROXY if you set it in the same window. Every curl proxy option, with examples, is on cURL with a proxy.

Choose the location, rotate IPs or keep one

The location goes in the username, as in <login>-country-us-city-new_york for a New York IP. Rotation gives a new IP on every request, so a loop gets a new address every time:

PowerShell
foreach ($i in 1..5) {
    Invoke-RestMethod -Uri "https://api.ipify.org" -Proxy "http://gate.proxyfield.io:7000" -ProxyCredential $cred
    Start-Sleep -Seconds 1
}

You don't need a list of proxies to rotate through: one gateway address does it. When a script must keep one IP, for a login or a checkout flow, use a sticky session, which holds the IP for 30 s to 36 h (presets 1, 5, 10, 30 min, 1, 3, 6 h). Session syntax: -region-<region>, -session-<id> and -ttl-<seconds> (30 to 129,600 seconds, 20 minutes by default) after the location, as in <login>-country-us-region-new_york-city-new_york-session-he9f2qga-ttl-600. Targeting and session options are on targeting, and when to use which on sticky vs rotating proxies.

ProxyField runs unlimited concurrent threads, so ForEach-Object -Parallel in PowerShell 7 can send many requests at once through the same gateway; pass the credential into the block with $using:cred.

Install modules through a proxy

Install-Module and Find-Module (PowerShellGet 2.x) have their own -Proxy and -ProxyCredential parameters:

PowerShell
Install-Module -Name PSParseHTML -Proxy "http://gate.proxyfield.io:7000" -ProxyCredential $cred

Install-PSResource, the newer installer in PowerShell 7, has no proxy parameter. It follows the session's default proxy, so set [System.Net.Http.HttpClient]::DefaultProxy or $env:HTTPS_PROXY as above first. If your company network already requires its own proxy for such downloads, use that one; a ProxyField proxy is for reaching sites from the IP and location you choose.

Check that PowerShell uses the proxy

  1. In PowerShell 7, run Invoke-RestMethod https://api.ipify.org once with the proxy and once with -NoProxy: the two IPs should differ.
  2. Invoke-RestMethod https://ipinfo.io/json -Proxy "http://gate.proxyfield.io:7000" -ProxyCredential $cred shows the exit IP's city and country.
  3. [System.Net.Http.HttpClient]::DefaultProxy.GetProxy("https://example.com") shows which proxy PowerShell 7 would use for a site, if any.
  4. netsh winhttp show proxy shows the services' proxy, and the registry lines above show the user's.
  5. To test a proxy line before you put it in a script, use the proxy checker.

Fix PowerShell proxy errors

Error or symptomLikely causeFix
Response status code does not indicate success: 407 (Proxy Authentication Required)No credential, a wrong password, or the login written into -ProxyPass -ProxyCredential; copy the username and password from your account
The proxy tunnel request to proxy '…' failed with status code '407'The same login problem, on an https:// siteAs above
SOCKS server did not return a suitable authentication methodA SOCKS5 login in the URL instead of -ProxyCredentialPass -ProxyCredential, or use $env:ALL_PROXY
No such host is known for the gatewayA typo in gate.proxyfield.io, or no DNSCheck the address; Resolve-DnsName gate.proxyfield.io
The proxy is ignored$env:HTTPS_PROXY set after the first request, or DefaultWebProxy used in PowerShell 7Open a new window and set the variable first; in PowerShell 7 use HttpClient.DefaultProxy
curl rejects -x in Windows PowerShell 5.1curl is the Invoke-WebRequest alias thereType curl.exe
Some sites won't loadThe site blocks the IP, or a restricted categorySome site categories are restricted to protect the network, including financial and government services

PowerShell sends the login only after the proxy asks for it, so a 407 followed by a success in a proxy log is normal. Gateway error messages: 407 Proxy Authentication Required for a wrong login or password, an IP not on the allowlist or a malformed location, 402 Payment Required when no traffic is left and 502 Bad Gateway when no exit could be connected; a restricted site gets no separate response, and a 403 comes from the site itself. The 407 status is explained in 407 Proxy Authentication Required, and other codes in proxy errors. Our 24/7 live chat helps with setup and integration.

Which proxies to use with PowerShell

What your script doesProxyPrice
Collects public pages and APIs, checks prices or rankings by country or cityResidentialfrom $1.95/GB ($2.95 for 1 GB)
Checks what phone users seeMobile 5G/4Gfrom $2.45/GB ($3.45 for 1 GB)
Logs in to one account from one fixed IP every dayDedicated ISPfrom $2.29 per IP per 30 days
Needs pages rendered with JavaScript, which Invoke-WebRequest can't doWeb Scraping APIJS rendering $2.00 per 1,000 successful results, down to $1.00

Web Scraping API: through Contact sales

Invoke-WebRequest returns the HTML the server sends and never runs a page's scripts; web scraping with Excel VBA and PowerShell shows how to parse that HTML and call a page's JSON instead. Use ProxyField for lawful work within our acceptable use policy, and respect each site's terms.

Get started

Start with the Easy Trial: 1 GB for $2.95, with no minimum purchase and no subscription. The traffic never expires and all purchases are final. See pricing per GB.

PowerShell Proxy Setup FAQ

How do I use a proxy in PowerShell?

ProxyField works in PowerShell from $1.95/GB: pass -Proxy "http://gate.proxyfield.io:7000" and -ProxyCredential $cred to Invoke-WebRequest or Invoke-RestMethod, where $cred holds your ProxyField username and password. The same http:// address works for https:// sites. Start with the Easy Trial: 1 GB for $2.95.

Does PowerShell use the Windows proxy settings?

Yes, by default. PowerShell 7 on Windows uses the proxy from Settings when no HTTPS_PROXY variable is set, and Windows PowerShell 5.1 does too. It doesn't use the WinHTTP proxy that netsh winhttp sets.

How do I set a proxy for every command in a PowerShell session?

In PowerShell 7, set [System.Net.Http.HttpClient]::DefaultProxy to a WebProxy with your credentials, or add Proxy and ProxyCredential for both web cmdlets to $PSDefaultParameterValues. Proxy environment variables also work if you set them before the session's first web request. Put the lines in your $PROFILE to keep them in new windows.

How do I set a proxy for PowerShell itself, for Install-Module and other cmdlets?

Install-Module and Find-Module take -Proxy and -ProxyCredential directly. Install-PSResource has no proxy parameter and follows the session's default proxy, so set [System.Net.Http.HttpClient]::DefaultProxy or $env:HTTPS_PROXY first. On a company network, use the proxy your administrator gives you for such downloads.

How do I set a proxy in Windows PowerShell 5.1?

Pass -Proxy and -ProxyCredential to each web cmdlet, as in PowerShell 7. For the whole session, assign a System.Net.WebProxy with your credentials to [System.Net.WebRequest]::DefaultWebProxy. That property has no effect in PowerShell 7.

How do I set the Windows proxy server from PowerShell?

Write it to the user's registry key HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings: ProxyServer = the gateway and port, ProxyOverride for local addresses, and ProxyEnable = 1 (0 turns it off). Apps that use the system proxy follow it after a restart. The system proxy has no login field: with your IP on the allowlist, use gate.proxyfield.io and the port you set up in the dashboard; with gate.proxyfield.io:7000, the browser asks for your username and password.

Can PowerShell use a SOCKS5 proxy?

PowerShell 7 can: it takes a -Proxy "socks5://host:port" address with -ProxyCredential, and hostnames are resolved at the proxy. Windows PowerShell 5.1 can't, so use curl.exe --socks5-hostname there or install PowerShell 7. ProxyField's SOCKS5 runs on the same gate.proxyfield.io:7000 with the same username and password.

How do I use curl with a proxy in PowerShell?

Type curl.exe, not curl, and use curl's options: curl.exe -x http://gate.proxyfield.io:7000 -U "<login>:<password>" https://api.ipify.org. curl.exe ships with Windows 10 and 11 and also reads $env:HTTPS_PROXY.

Do you need a proxy for PowerShell web scraping?

Not for a few requests to one site. You need one when a site limits requests per IP, shows different content by country or city, or your script runs many requests in parallel. A rotating residential proxy gives each request a new IP from one gateway address.

How do I choose the right way to configure a proxy in PowerShell?

Choose by what must use the proxy. One request: -Proxy on the cmdlet; a whole script: $PSDefaultParameterValues or HttpClient.DefaultProxy; child programs such as curl.exe too: environment variables; browsers and apps: the Windows system proxy; Windows services: netsh winhttp.

Show 9 more questionsShow fewer questions

How do I authenticate to a proxy in PowerShell?

Create a credential with [pscredential]::new("<login>", (ConvertTo-SecureString $env:PROXY_PASS -AsPlainText -Force)) and pass it to -ProxyCredential. A login written into the -Proxy address is not sent. With an IP allowlist, you don't pass a credential at all, and -Proxy uses the port you set up in the dashboard instead of 7000.

Which proxy protocol should I use in PowerShell: HTTP, HTTPS or SOCKS5?

Use an http:// proxy address for most scripts: it carries https:// sites through an encrypted tunnel, the proxy resolves the hostnames, and it works in every PowerShell version. PowerShell 7 also accepts a socks5:// address; SOCKS5 runs on the same gate.proxyfield.io:7000 with the same username and password.

How do I rotate proxies in PowerShell?

With rotation you don't keep a list: call the same -Proxy address in a loop, and each request gets a new IP. When several requests must share one IP, use a sticky session, which holds it for 30 s to 36 h.

How do I use netsh to set a proxy from PowerShell?

In an elevated PowerShell window, run netsh winhttp set proxy proxy-server="gate.proxyfield.io:7000" bypass-list="<local>", or netsh winhttp import proxy source=ie to copy the user's proxy. It changes only the WinHTTP proxy used by Windows services, not PowerShell's own web cmdlets.

Why does Invoke-WebRequest return 407 Proxy Authentication Required?

The proxy got no login or a wrong one. Pass -ProxyCredential with the username and password from your account, and don't put them in the -Proxy URL, where PowerShell ignores them. On https:// sites the same problem reads "The proxy tunnel request to proxy … failed with status code '407'".

What's the alternative to Invoke-WebRequest?

Invoke-RestMethod for JSON and XML APIs, curl.exe for curl's options, and .NET's HttpClient for full control from a script. Each takes a proxy: -Proxy for the cmdlet, -x for curl and a WebProxy in an HttpClientHandler for .NET.

Why does PowerShell ignore my HTTPS_PROXY variable?

PowerShell 7 reads the proxy variables once, at the session's first web request, so a variable set after that is ignored until you open a new window. Set it first, or set [System.Net.Http.HttpClient]::DefaultProxy, which takes effect at once. Windows PowerShell 5.1 doesn't read these variables for its cmdlets.

How do I check that PowerShell is using the proxy?

In PowerShell 7, run Invoke-RestMethod https://api.ipify.org with the proxy and again with -NoProxy; the two IPs should differ. https://ipinfo.io/json through the proxy also shows the exit IP's city and country.

How do I choose the proxy's country or city in PowerShell?

Put it in the username of the credential: <login>-country-us-city-new_york, for example, gives a New York IP. Targeting covers country, region (state) and city, all 50 US states; other locations take the same keys: -country-<cc>, -region-<region> and -city-<city>.

Easy Trial: 1 GB for $2.95.

Try for the price of 1 GB, no subscription, traffic never expires.