Skip to content

Instantly share code, notes, and snippets.

@harmakhis971
Forked from hugefiver/set_proxy.ps1
Created August 23, 2023 07:59
Show Gist options
  • Save harmakhis971/f7754a23b26f7b6254d09f81e7f4a7d5 to your computer and use it in GitHub Desktop.
Save harmakhis971/f7754a23b26f7b6254d09f81e7f4a7d5 to your computer and use it in GitHub Desktop.
powershell set default proxy for `Invoke-WebRequest`
# set to system default proxy
[System.Net.WebRequest]::DefaultWebProxy = [System.Net.WebRequest]::GetSystemWebProxy()
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
# or a custom one
[System.Net.WebRequest]::DefaultWebProxy = New-Object System.Net.WebProxy("http://localhost:8080")
# or use username and password auth
[System.Net.WebRequest]::DefaultWebProxy = New-Object System.Net.WebProxy("http://localhost:8080",$true)
[System.Net.WebRequest]::DefaultWebProxy.Credentials = New-Object System.Net.NetworkCredential($user, $passwd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment