PowerShell Proxy | How to set proxy for current session or permanently

01kg - Aug 20 - - Dev Community

TL;DR

Key code:

$proxyUrl = "http://your-proxy-url:port"
[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy($proxyUrl)
[system.net.webrequest]::defaultwebproxy.credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
Enter fullscreen mode Exit fullscreen mode

Replace "http://your-proxy-url:port" with your own proxy url and port.

For current session:

Input key code into your current PowerShell session.

Permanently

  1. Use Notepad to edit PowerShell Profile: notepad $PROFILE
  2. Optional: If File Explorer alert that cannot find this file, you should create One: New-Item -Path $PROFILE -ItemType File -Force
  3. Add key code into this profile. Save.
  4. Open a new PowerShell session to apply this change
  5. Optional: If an error message indicates that the execution of scripts is disabled on your system due to the current PowerShell execution policy in the new session, do:
    1. Right-click on the PowerShell icon and select "Run as Administrator".
    2. Run the following command to set the execution policy to RemoteSigned, which allows scripts created on your local computer to run: Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .