|
# do not change this unless you know what you are doing |
|
$registryPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" |
|
# your pac proxy or if you proxy software provides an automatic proxy url, for example: http://127.0.0.1:8080/pac.pac, if none, leave it alone |
|
$automaticproxy = "" |
|
# the manual proxy url, for example: xxx.com:80, if none, leave it alone |
|
$proxy = "" |
|
# urls/paths you don't want to be proxied, comma seperated string, for example: ::1,localhost,127.0.0.1, if none, leave it alone |
|
$noproxy = "" |
|
|
|
# set system-wide environment for powershell/cmd proxy |
|
function set_proxy_variable { |
|
# modify system environment for the current user |
|
[System.Environment]::SetEnvironmentVariable("ALL_PROXY", $proxy, "User") |
|
[System.Environment]::SetEnvironmentVariable("HTTP_PROXY", $proxy, "User") |
|
[System.Environment]::SetEnvironmentVariable("HTTPS_PROXY", $proxy, "User") |
|
[System.Environment]::SetEnvironmentVariable("NO_PROXY", $noproxy, "User") |
|
|
|
Write-Host "`nCommand line proxy enabled!`n" |
|
} |
|
|
|
# unset system-wide environment for powershell/cmd proxy |
|
function unset_proxy_variable { |
|
# modify system environment for the current user |
|
[Environment]::SetEnvironmentVariable("ALL_PROXY", $null, "User") |
|
[Environment]::SetEnvironmentVariable("HTTP_PROXY", $null, "User") |
|
[Environment]::SetEnvironmentVariable("HTTPS_PROXY", $null, "User") |
|
[Environment]::SetEnvironmentVariable("NO_PROXY", $null, "User") |
|
|
|
Write-Host "`nCommand line proxy disabled!`n" |
|
} |
|
|
|
# set IE proxy, which is much harder and here is not a perfect solution, but it works |
|
function set_IE_proxy { |
|
if ($automaticproxy) { |
|
# set and enable auto proxy |
|
Set-ItemProperty -Path $registryPath -Name AutoConfigURL -Value $automaticproxy |
|
|
|
# disable and remove manual proxy |
|
Set-ItemProperty -Path $registryPath -Name ProxyEnable -Value 0 |
|
Remove-ItemProperty -Path $registryPath -Name ProxyServer |
|
|
|
Write-Host "`nIE auto proxy enabled!`n" |
|
} |
|
else if ($proxy) { |
|
Set-ItemProperty -Path $registryPath -Name ProxyEnable -Value 1 |
|
Set-ItemProperty -Path $registryPath -Name ProxyServer -Value $proxy |
|
Set-ItemProperty -Path $registryPath -Name ProxyOverride -Value $noproxy |
|
|
|
Write-Host "`nIE manual proxy enabled!`n" |
|
} |
|
else { |
|
Write-Host "`nNo valid IE proxy to be enabled!`n" |
|
} |
|
} |
|
|
|
# unset IE proxy |
|
function unset_IE_proxy { |
|
# unset auto proxy |
|
Remove-ItemProperty -Path $registryPath -Name AutoConfigURL |
|
|
|
# disable manual proxy |
|
Set-ItemProperty -Path $registryPath -Name ProxyEnable -Value 0 |
|
|
|
Write-Host "`nIE proxy disabled!`n" |
|
} |
|
|
|
function enable_proxy { |
|
set_IE_Proxy |
|
set_proxy_variable |
|
|
|
Write-Host "`n System-wide proxy enabled!`n" |
|
} |
|
|
|
function disable_proxy { |
|
unset_IE_Proxy |
|
unset_proxy_variable |
|
|
|
Write-Host "`n System-wide proxy disabled!`n" |
|
} |
|
|
|
Set-Alias proxy enable_proxy |
|
Set-Alias unproxy disable_proxy |