r/PowerShell • • May 11 '26

Question How to set manual proxy IP and port

I'm trying to figure out how to create a script to set a manual proxy IP address and port but I'm not sure how.

Edit: I'm a still a beginner trying to learn at the moment.

2 Upvotes

11 comments sorted by

1

u/Particular_Fish_9755 May 11 '26

AD? Intune? Local?
For all ports or only certain ones that need to go through the proxy?
Is there authentication on the proxy server?

Basically, this can be done using the netsh command with the associated parameters.
https://learn.microsoft.com/en-en/windows-server/administration/windows-commands/netsh-winhttp

1

u/asiansinger May 11 '26

So what I'm looking for is the Windows LAN proxy settings. I'm not sure if netsh includes that but there's no authentication on the proxy server but there's a specific port it does go through

1

u/Particular_Fish_9755 May 12 '26

Either by referring to the documentation I previously mentioned, by specifying the proxy address with its port, and for it to be used for the entire machine and not just the user:

netsh winhttp set advproxy setting-scope=machine settings="{\"Proxy\":\"http=http-proxy.com:8080;https=https-proxy.com:8081;ftp=ftp-proxy.com:8082;socks=socks-proxy.com:8083\",\"ProxyBypass\":\"\",\"AutoconfigUrl\":\"\",\"AutoDetect\":true}"

This involves having one proxy server that handles HTTP traffic, another on a different port for HTTPS, another for FTP, and a final one for other connections.

Then there are PowerShell environment variables, but I don't know how they are used:

$env:HTTPS_PROXY="http-proxy.com:8080"
$env:HTTP_PROXY="https-proxy.com:8081"
$env:all_proxy="socks5://socks-proxy.com:8083"

0

u/[deleted] May 11 '26

[removed] — view removed comment

2

u/Thotaz May 11 '26

as netsh has been deprecated

Source? I can find no documentation saying this. The closest thing is this: https://learn.microsoft.com/en-us/troubleshoot/windows-server/networking/netsh-advfirewall-firewall-control-firewall-behavior which states that netsh firewall has been deprecated and that netsh advfirewall is the new preferred method to manage firewall settings. In fact, the WinhttpProxy commands even use netsh under the hood:

PS C:\WINDOWS\system32> (Get-Command Get-WinhttpProxy).Definition

    param
    (
        [parameter(mandatory, parametersetname="Default")]
        [switch]
        $Default,

        [parameter(mandatory, parametersetname="Advanced")]
        [switch]
        $Advanced
    )

    if ($Default)
    {
        netsh winhttp show proxy
...

1

u/asiansinger May 11 '26

Not sure if this helps but what I'm looking for is specifically through the Windows LAN proxy settings under Internet Options. There's no authentication on it but just needs the IP and port number and that's it.

-1

u/[deleted] May 11 '26

[removed] — view removed comment

1

u/Thotaz May 11 '26

While I wish PowerShell had the kind of buy-in at Microsoft as you are suggesting, that is unfortunately not the case.
Most on-prem product teams at MS support their own native client first and foremost with the PowerShell module (if it even exists) as a secondary priority.
Notable examples include: Dism, schtasks, winget, bcdedit, pnputil. All of these native tools have a PowerShell module available, but the native tool supports more features and/or is less buggy.
An example of this is if you try to set a static IP address on a disconnected NIC with the PowerShell command, you'll get an error like this:

PS C:\> New-NetIPAddress -IPAddress 192.168.20.5 -PrefixLength 24 -InterfaceAlias 'Ethernet 2'
New-NetIPAddress: Inconsistent parameters PolicyStore PersistentStore and Dhcp Enabled
PS C:\>

If you use netsh.exe interface ipv4 set address name="Ethernet 2" static 192.168.20.5 255.255.255.0 then it works without any fuss.

0

u/BlackV May 11 '26

would be nice that if instead of adding a tonne of AI slop to windows 12 the spend a tonne of effort removing the win32 crud that still hangs around in the OS

feck backwards compatibility