Thursday, September 29, 2011

Prox on, Prox off: Windows Proxy On, Windows Proxy Off with PowerShell



These four files will give you the ability to switch between
having a proxy server set in Windows and not having one set 
without having to navigate a bunch of windows each time. 

Because Windows won't allow a PowerShell script to execute by 
default the scripts are called using batch files so the execution 
policy can be altered before and after calling the script.


proxyon.ps1:

set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name MigrateProxy -value 1
set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyEnable -value 1
set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyHttp1.1 -value 0
set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyServer -value 'http://10.1.10.109:3128'
set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyOverride -value '<local>'

proxyoff.ps1:

set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name MigrateProxy -value 1
set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyEnable -value 0
set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyHttp1.1 -value 0
set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyServer -value ''
set-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyOverride -value '<local>'



poff.bat:
 
powershell {Set-ExecutionPolicy Unrestricted}
powershell "& C:\proxyoff.ps1"
powershell {Set-ExecutionPolicy Restricted}

pon.bat:

powershell {Set-ExecutionPolicy Unrestricted}
powershell "& C:\proxyon.ps1"
powershell {Set-ExecutionPolicy Restricted}
 

4 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete