Skip to content

Instantly share code, notes, and snippets.

@francisoud
Created May 31, 2017 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save francisoud/f594adc161182da97f2dfdb7aa13c3a5 to your computer and use it in GitHub Desktop.
Save francisoud/f594adc161182da97f2dfdb7aa13c3a5 to your computer and use it in GitHub Desktop.
Auto configure windows proxy based on IP (home/work)
# Run this script: create a .cmd in "startup" menu
# Powershell -File %USERPROFILE%\proxy-auto-config.ps1
# Powershell.exe -executionpolicy remotesigned -File %USERPROFILE%\proxy-auto-config.ps1
# Use fixed IP address with DHCP and associate MAC address with fixed IP(s) (wifi/cable)
# Change IP mask bellow
# Sources:
# https://forums.manageengine.com/topic/setting-proxy-server-based-on-ip-address
# https://technet.microsoft.com/itpro/powershell/windows/nettcpip/get-netipaddress
# https://social.technet.microsoft.com/Forums/windowsserver/en-US/d4051879-1a50-499a-a188-2a9b33004c96/configure-ie-proxy-settings-based-on-ip-address?forum=winserverpowershell
# https://stackoverflow.com/questions/21568502/ie-enable-disable-proxy-settings-via-registry
# $PSVersionTable 2.x
$CurrentIP = gwmi Win32_NetworkAdapterConfiguration |
Where { $_.IPAddress } | # filter the objects where an address actually exists
Select -Expand IPAddress | # retrieve only the property *value*
Where { $_ -like '192.168.0.3*' }
Write-Host $CurrentIP
If ($CurrentIP) {
Write-Host "@home"
Set-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" AutoConfigURL -value ""
# Set-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ProxyEnable -value 0
# ProxyServer x.x.x.x et ProxyOverride <local>
} Else {
Write-Host "Not @home"
Set-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" AutoConfigURL -value "http://172.16.70.8/proxy_websense.pac"
# Set-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ProxyEnable -value 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment