Home > powershell, random > Powershell script to set proxy settings and toggle automatically detect settings in Internet Explorer

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


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:

http://justdaft.wordpress.com/2012/05/31/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

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: