SCRIPT: Automatically Change Proxy Settings

When you’re in the consulting business, you travel a lot between companies. That what I consider the beautiful part of the job. Downside is that every company has it’s own policy for Internet usage. A lot of companies regulate their internet access through so called proxy servers. When you visit a lot of companies you have to change the internet settings multiple times a day to match the desired settings for that company. Therefore I wrote a powershell script that detects the DNS suffix of the company you’re at and matches the proxy settings according to the configured settings read from a XML file.

What does the script do:

  • Change Proxy Server settings for Internet Explorer and Chrome
  • Add Proxy Exceptions to bypass the proxy
  • When connected to multiple networks a known location takes presence
  • When a location is not known, the configuration defaults to “Direct Connection”
  •  Notifies you which settings are used.

What the script does NOT do:

  • Detect networks based on IP Address (Never will, too general way of checking)
  • Change Proxy settings for FireFox (#1 on my wishlist)
  • Detect network changes dynamically.

Installation/Configuration

Copy the PS1 and XML to a convinient location (eg. C:\Windows). Configure the XML file for use with proxy servers. Each location must be in its own <Sites> node.

<Name>  The name for your location is must be in the Name node.
<DNSDomain> The DNS Domain that should be checked is in this node
<ProxyServer> In this node you enter the proxy server name
<ProxyPort> In this node you enter the proxy port that should be used
<ProxyOverRide> All exceptions that should bypass the proxy server are entered in this node, each exception should be separated with a semi column.

Example Configuration

<Sites>
 <Name>My Location</Name>
 <DNSDomain>company-a.com</DNSDomain>
 <ProxyServer>www-proxy.company-a.com</ProxyServer>
 <ProxyPort>8080</ProxyPort>
 <ProxyOverRide>intranet.company-a.com;dev.company-a.com;</ProxyOverRide>
 </Sites>

Each location should look like the above example, you can append multiple sites to the <Global> node. I’ve tested the script on Windows 7 (x64) but it should work on Windows XP as well. to hide the Powershell command-box you can start the powershell script with:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -WindowStyle “Hidden” C:\Windows\SetProxy.ps1

I’ve created a scheduled task that executes the script on login and unlock, that covers it for me. additionaly you can create a shortcut on your desktop to launch the script manually.

Please let me know what you think.

Download :  Set Proxy (2931)

2 Comments to “SCRIPT: Automatically Change Proxy Settings”

  1. […] So I wondered…could I use PowerShell to change my Proxy Settings. A quick search lead me to a couple of blog entries that talked about it and decided to adapt it to my own […]

  2. vladyn 5 December 2014 at 15:56 #

    This is really good stuff – thank you!


Leave a Reply