PowerShell is a task-oriented command line shell and scripting environment developed by Microsoft designed to control numerous activities on Windows operating systems. Among its primary functions is the ability to perform proxy configuration. The command line and its ability to run such tasks enhances the automation and ease of the central management of network settings of devices on the domain.
The main advantage of configuring a proxy server using PowerShell as compared to other common methods is that it does not require a graphical interface since it directly alters the internet connection settings. This feature is particularly useful for system administrators who need to monitor proxy server settings on various devices since they will be able to quickly change the settings and add them into other scripts that are already automated for more efficiency.
There are two main approaches to the configuration of proxy servers system-wide using PowerShell: using netsh commands to control the WinHTTP service and editing registry keys with the Set-ItemProperty command . Specifically, this section focuses on these two methods and provides a few practical examples for effective proxy settings for the whole system, and its applications. This dual approach allows administrators to work with network settings more efficiently on different levels.
The netsh command is embedded into Windows OS and serves a lot of purposes. One of the functions that can be performed by this command is configuring proxy settings in relation to the WinHTTP service. This allows the user to change the way system services operate rather than changing proxies within applications or browsers that support different types of networks.
It is important to emphasize that the use of the netsh command in PowerShell is limited to proxies that use IP authorization and not to proxies that require login credentials.
Here’s how you can configure proxy settings using PowerShell:
netsh winhttp set proxy IP-address:port
To view current proxy settings such as address and port use:
netsh winhttp show proxy
To remove proxy settings:
netsh winhttp reset proxy
Proxy settings may be managed centrally in PowerShell by configuring the registry system manually. This method impacts any programs that use the Windows system to manage their network settings, which includes nearly all web browsers.
For adding proxy settings that do not require any authorization, you can apply the following PowerShell commands:
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyServer -Value "IP address:port"
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyEnable -Value 1
If you are using a private proxy that needs login information, here is how to proceed:
$proxyAddress = "http://IP address:port"
# Here we specify the address of the required proxy server
$credentials = Get-Credential
# You will be prompted to input the username and password with this command
[system.net.webrequest]::DefaultWebProxy = New-Object system.net.webproxy($proxyAddress)
# Creates a new proxy object with the specified address
[system.net.webrequest]::DefaultWebProxy.Credentials = $credentials
# Apply the credentials previously input to the proxy
If you would like to turn off the proxy settings use the following command:
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyEnable -Value 0
There are several measures that can be applied when there are difficulties in executing proxy settings. Below are the important commands and techniques for troubleshooting.
Your current settings for proxy can easily be checked by utilizing the command as follows:
Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" | Select-Object ProxyServer, ProxyEnable
For the purpose of establishing whether the proxy by any chance is forwarding your network requests, the following command may be utilized to ping a known site, say example.com, at a standard HTTP port.
Test-NetConnection -ComputerName "example.com" -Port 80
Any website of your choice can be put instead of “example.com” if needed.
If you still encounter issues connecting via a proxy, you should check all the settings once again. Make sure that the details given by your proxy provider are correct and the proxy itself is working.
Comments: 0