If you’re using PowerShell for network configuration, you may need to set or unset a proxy for a variety of reasons, whether you’re trying to bypass network restrictions, secure your internet traffic, or troubleshoot issues.
PowerShell provides powerful commands to configure your system’s network settings, including setting up and unsetting proxies.
In this guide, we’ll show you how to unset a proxy in PowerShell, use a simple proxy with PowerShell, and set up a proxy in your network settings. Let’s get started!
What is a Proxy?
A proxy is an intermediary server that routes your internet traffic on your behalf. When using a proxy, instead of connecting directly to websites, your requests are sent to the proxy server, which forwards the request to the website, receives the response, and sends it back to you.
This helps mask your real IP address, improve security, and can allow you to bypass geo-restrictions or network filters.
Tired of Proxy Problems? Upgrade to Multilogin Now for Superior Proxy Management.
How to Unset Proxy in PowerShell
Sometimes you may need to unset a proxy or disable it if you no longer need to route traffic through a proxy server. PowerShell makes it easy to do this. Here’s how you can unset the proxy settings on a Windows machine:
Steps to Unset Proxy Using PowerShell
- Open PowerShell:
- Press Windows + X, then select Windows PowerShell (Admin) to open PowerShell with administrative privileges.
Check Current Proxy Settings: Before unsetting the proxy, you can check your current proxy settings with the following command:
netsh winhttp show proxy
- This will display the current proxy settings on your system.
Unset the Proxy: To unset or remove the proxy configuration, use the following command:
netsh winhttp reset proxy
- This command removes the configured proxy and sets your system to connect to the internet directly without routing traffic through a proxy.
Verify the Proxy is Removed: Run the command again to ensure the proxy settings have been removed:
netsh winhttp show proxy
- Now your system will no longer use a proxy server for internet access.
How to Use Simple-Proxy with PowerShell
If you want to route your PowerShell requests through a simple proxy, you can use a proxy server with PowerShell’s Invoke-WebRequest or Invoke-RestMethod commands.
Setting Up Simple-Proxy with PowerShell
- Open PowerShell: Launch PowerShell with administrative rights as described earlier.
- Set Proxy Variables: Define the proxy server and port you wish to use. For example, if you’re using a SOCKS proxy or an HTTP proxy, set the proxy URL:
$proxy = "http://your_proxy_server:your_proxy_port"
- Send Request Through Proxy: Use the Invoke-WebRequest command with the -Proxy parameter to route your web requests through the proxy:
Invoke-WebRequest -Uri "http://example.com" -Proxy $proxy
- Send Request with Proxy Authentication (if needed): If your proxy requires authentication, use the -ProxyCredential parameter:
$proxyCredential = Get-Credential
Invoke-WebRequest -Uri "http://example.com" -Proxy $proxy -ProxyCredential $proxyCredential
- This way, PowerShell sends your requests through the simple proxy you’ve defined.
How to Set Up a Proxy in PowerShell
To set up a proxy in PowerShell, you can configure system-wide proxy settings that will apply to all applications using the system’s network configuration.
Steps to Set Up a Proxy Using PowerShell
- Open PowerShell: Open Windows PowerShell with administrative privileges.
Set Proxy Server: Use the following command to set up the proxy server for HTTP and HTTPS:
netsh winhttp set proxy proxy-server="http://your_proxy_server:your_proxy_port" proxy-bypass-list="*.example.com"
- In this command:
- Replace your_proxy_server with the IP address or domain name of the proxy server.
- Replace your_proxy_port with the proxy’s port number (commonly 8080 or 3128).
- The proxy-bypass-list parameter defines websites or domains that should bypass the proxy server. In this case, *.example.com will allow websites from the example.com domain to connect directly without using the proxy.
Verify Proxy Configuration: To check if the proxy has been set up correctly, use the command:
netsh winhttp show proxy
- Set Proxy with Authentication (Optional): If your proxy requires a username and password, you can configure authentication with a credential:
$proxyCredential = Get-Credential
$proxy = "http://your_proxy_server:your_proxy_port"
Invoke-WebRequest -Uri "http://example.com" -Proxy $proxy -ProxyCredential $proxyCredential
- Persistent Proxy Settings: If you want the proxy settings to be persistent and automatically applied at system startup, you need to configure it through the Windows settings or through scripts that run at startup.
Troubleshooting Proxy Issues in PowerShell
Sometimes, configuring a proxy may not work as expected, and troubleshooting is necessary. Here are some common issues and solutions:
- Proxy Not Working: If the proxy doesn’t work, check that you’ve entered the correct proxy address and port number. Ensure the proxy server is online and accessible.
- Network Blocked by Proxy: If you encounter connection issues after setting up a proxy, the network might be blocking access to certain sites. Try bypassing the proxy for specific domains using the proxy-bypass-list as shown above.
- Authentication Issues: If your proxy requires authentication, make sure to provide the correct credentials using Get-Credential. Incorrect usernames or passwords will cause authentication failures.
- Proxy Timeouts: If requests through the proxy time out, it could be due to an overloaded proxy server or poor connection. You can test the proxy’s speed by using tools like ping or traceroute.
Frequently Asked Questions About Proxy Configuration in PowerShell
How do I unset a proxy in PowerShell?
To unset a proxy in PowerShell, you can use the command:
netsh winhttp reset proxy
This command will remove the proxy settings and restore direct internet access.
How can I set up a proxy in PowerShell?
To configure a proxy in PowerShell, use the following command:
netsh winhttp set proxy proxy-server="http://your_proxy_server:your_proxy_port" proxy-bypass-list="*.example.com"
Replace your_proxy_server and your_proxy_port with the correct proxy address and port number.
Can I configure a proxy for a specific application using PowerShell?
Yes, you can set up a proxy for specific applications by routing their traffic through the configured proxy in PowerShell. For example, with web scraping tools or API requests, you can use PowerShell’s Invoke-WebRequest or Invoke-RestMethod commands to route specific traffic through the proxy.
What should I do if my proxy is not working in PowerShell?
If your proxy isn’t working, ensure that the proxy server is running and accessible, and that you’ve entered the correct proxy address and port number. Check the proxy provider for any known issues, or try using a different proxy server.
Final Thoughts
Configuring a proxy in PowerShell is a straightforward process, whether you’re setting up a simple proxy for web requests or configuring system-wide proxy settings. Proxies offer a wide range of benefits, such as enhanced privacy, security, and the ability to bypass geo-restrictions.
However, it’s important to ensure that the proxy server you’re using is reliable and responsive to avoid issues like slow speeds and connection failures.
Whether you’re unsetting proxy settings, using a simple proxy for web requests, or setting up a proxy server for your system, PowerShell makes it easy to manage your network traffic.