Set Proxy

Code Properties

  • Language: PowerShell
  • Class: System.Net.WebRequest

Overview

PowerShell command to set the default web proxy for .NET web requests, useful when behind a proxy server.

Code

[Net.WebRequest]::DefaultWebProxy = New-Object Net.WebProxy "http://127.0.0.1:7890"

Usage

# set proxy
[Net.WebRequest]::DefaultWebProxy = New-Object Net.WebProxy "http://proxy.example.com:8080"
 
# set proxy with credentials
$proxy = New-Object Net.WebProxy "http://proxy.example.com:8080"
$proxy.Credentials = [Net.CredentialCache]::DefaultCredentials
[Net.WebRequest]::DefaultWebProxy = $proxy
 
# clear proxy
[Net.WebRequest]::DefaultWebProxy = $null

Appendix

Note created on 2024-05-03 and last modified on 2024-12-31.

See Also


(c) No Clocks, LLC | 2024