Created
July 23, 2024 18:11
-
-
Save crosstyan/abb96ad4b26a1d13604c1d7894b97f1e to your computer and use it in GitHub Desktop.
set proxy environment variable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set-ExecutionPolicy -ExecutionPolicy Unrestricted | |
$proxy_host = "http://192.168.5.2" | |
$proxy_port = 36000 | |
$before_path = Get-Location | |
function remove-env($name) { | |
$before= Get-Location | |
try { | |
# https://stackoverflow.com/questions/8388650/powershell-how-can-i-stop-errors-from-being-displayed-in-a-script | |
Set-Location Env: | |
Remove-Item $name -ErrorAction Stop | Out-Null | |
} catch {} finally { | |
Set-Location $before | |
} | |
} | |
remove-env "http_proxy" | |
remove-env "https_proxy" | |
remove-env "no_proxy" | |
remove-env "HTTP_PROXY" | |
remove-env "HTTPS_PROXY" | |
remove-env "NO_PROXY" | |
$env:HTTP_PROXY = "${proxy_host}:${proxy_port}" | |
$env:HTTPS_PROXY = "${proxy_host}:${proxy_port}" | |
# https://en.wikipedia.org/wiki/Reserved_IP_addresses | |
$env:NO_PROXY = "localhost,127.0.0.1,127.0.0.0/8,192.168.0.0/16,10.0.0.0/8,172.16.0.0/12" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function remove-env($name) { | |
$before= Get-Location | |
try { | |
# https://stackoverflow.com/questions/8388650/powershell-how-can-i-stop-errors-from-being-displayed-in-a-script | |
Set-Location Env: | |
Remove-Item $name -ErrorAction Stop | Out-Null | |
} catch {} finally { | |
Set-Location $before | |
} | |
} | |
remove-env "http_proxy" | |
remove-env "https_proxy" | |
remove-env "no_proxy" | |
remove-env "HTTP_PROXY" | |
remove-env "HTTPS_PROXY" | |
remove-env "NO_PROXY" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment