Archive

Archive for the ‘powershell’ Category

Powershell script to set proxy settings and toggle automatically detect settings in Internet Explorer

September 16, 2014 Leave a comment

on hourly basis I have to toggle proxy settings of my laptop because I need to switch between corporate proxy and other networks I access, so I thought about scripting it using a simple powershell script, here is the script (the script will set the proxy and toggle automatically detect settings off , or unset the proxy and turn automatically detect settings on), here is the script:

$regKey=”HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings”
$proxyServer = “”
$proxyServerToDefine = “IP:8080”
Write-Host “Retrieve the proxy server …”
$proxyServer = Get-ItemProperty -path $regKey ProxyServer -ErrorAction SilentlyContinue
Write-Host $proxyServer
$val = (get-itemproperty “HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections” DefaultConnectionSettings).DefaultConnectionSettings

$val[8] = $val[8] -bxor 8
if([string]::IsNullOrEmpty($proxyServer))
{
Write-Host “Proxy is actually disabled”

set-itemproperty “HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections” -name DefaultConnectionSettings -value $val
Set-ItemProperty -path $regKey ProxyEnable -value 1
Set-ItemProperty -path $regKey ProxyServer -value $proxyServerToDefine
Write-Host “Proxy is now enabled”
}
else
{

set-itemproperty “HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections” -name DefaultConnectionSettings -value $val
Set-ItemProperty -path $regKey ProxyEnable -value 0
Remove-ItemProperty -path $regKey -name ProxyServer

Write-Host “Proxy is now disabled”
}

References:

PowerShell, toggle IE auto detect setting

http://blogs.msdn.com/b/aymerics_blog/archive/2013/05/18/scripting-toggle-proxy-server-in-ie-settings-with-powershell.aspx