Set the Windows web proxy with PowerShell

2015-05-09 | Martin Hoppenheit | 2 min read

Usually the system wide web proxy settings on Windows are configured via the (graphical) Internet Explorer’s or the System Control’s internet options panel. However, sometimes it would be nice to do this with PowerShell.

It basically boils down to knowing the right registry entry:

PS> $reg = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"

Get the current proxy server and whether it is enabled:

PS> $settings = Get-ItemProperty -Path $reg
PS> $settings.ProxyServer
PS> $settings.ProxyEnable

Configure a proxy server and enable it:

PS> Set-ItemProperty -Path $reg -Name ProxyServer -Value ""
PS> Set-ItemProperty -Path $reg -Name ProxyEnable -Value 1

Disable the proxy:

PS> Set-ItemProperty -Path $reg -Name ProxyEnable -Value 0

And optionally remove the proxy server entry:

PS> Remove-ItemProperty -Path $reg -Name ProxyServer

Most of the above commands can be shortened for quick and dirty command line work, relying on built in aliases and the default order of parameters. An example:

PS> sp $reg ProxyEnable 0

This disables the proxy and is equivalent to the command above. It is your decision which variant is more suitable in a given situation.

There is a little script by Aymeric Mouillé on MSDN that toggles the proxy settings.

You should keep in mind that although the system proxy can be configured with PowerShell, PowerShell itself does not automatically use this proxy! See my previous blog post to learn how to configure PowerShell’s own proxy settings.