Last active
February 13, 2023 10:32
-
-
Save AliMilani/cf43983869441d4e1eb8c2c588ff542f to your computer and use it in GitHub Desktop.
set windows and cmd proxy with powershell (default gateway)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://martin.hoppenheit.info/blog/2015/set-windows-proxy-with-powershell/ | |
| $reg = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" | |
| $settings = Get-ItemProperty -Path $reg | |
| $port = 10809 | |
| # select the gateway ip address from the default route and extract the ip address | |
| $gateway = Get-NetRoute | | |
| where {$_.DestinationPrefix -eq '0.0.0.0/0'} | | |
| select { $_.NextHop } | |
| $gateway = $gateway -replace '.*?(\d+\.\d+\.\d+\.\d+).*', '$1' | |
| $cmd = "netsh winhttp set proxy ${gateway}:${port}" | |
| # $cmd | |
| Set-ItemProperty -Path $reg -Name ProxyServer -Value "${gateway}:${port}" | |
| Set-ItemProperty -Path $reg -Name ProxyEnable -Value 1 | |
| Invoke-Expression $cmd # need admin privilege | |
| # convert to exe with https://apps.microsoft.com/store/detail/powershell-to-exemsi-converter-free/XPDCHZH119SRT8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $reg = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" | |
| Set-ItemProperty -Path $reg -Name ProxyEnable -Value 0 | |
| netsh winhttp reset proxy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment