Forked from hygorluz/win_set_proxy_server_powershell.ps1
Created
March 8, 2024 05:35
-
-
Save BalajiVelaga/6d4a841d868d8f4d04c5734de4836e1c to your computer and use it in GitHub Desktop.
Set Windows Proxy Server via PowerShell
This file contains 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
#### | |
# SET-INTERNETPROXY | |
# | |
# DESCRIPTION | |
# This function will set the proxy server and (optional) Automatic configuration script. | |
# | |
# SYNTAX | |
# Set-InternetProxy [-Proxy] <string[]> [[-acs] <string[]>] [<CommonParameters>] | |
# | |
# EXAMPLES | |
# Set-InternetProxy -proxy "http=127.0.0.1:8080" | |
# Set-InternetProxy -proxy "https=127.0.0.1:8080" | |
# Set-InternetProxy -proxy "ftp=127.0.0.1:8080" | |
# Set-InternetProxy -proxy "socks=127.0.0.1:8080" | |
# Setting proxy information and (optinal) Automatic Configuration Script: | |
# Set-InternetProxy -proxy "proxy:7890" -acs "http://proxy:7892" | |
# | |
# SOURCE | |
# https://gallery.technet.microsoft.com/scriptcenter/PowerShell-function-Get-cba2abf5 | |
#### | |
Function Set-InternetProxy | |
{ | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory=$True,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] | |
[String[]]$Proxy, | |
[Parameter(Mandatory=$False,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] | |
[AllowEmptyString()] | |
[String[]]$acs | |
) | |
Begin | |
{ | |
$regKey="HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" | |
} | |
Process | |
{ | |
Set-ItemProperty -path $regKey ProxyEnable -value 1 | |
Set-ItemProperty -path $regKey ProxyServer -value $proxy | |
Set-ItemProperty -path $regKey ProxyOverride -value "<local>" | |
if($acs) | |
{ | |
Set-ItemProperty -path $regKey AutoConfigURL -Value $acs | |
} | |
} | |
End | |
{ | |
Write-Output "Proxy is now enabled" | |
Write-Output "Proxy Server : $proxy" | |
if ($acs) | |
{ | |
Write-Output "Automatic Configuration Script : $acs" | |
} | |
else | |
{ | |
Write-Output "Automatic Configuration Script : Not Defined" | |
} | |
} | |
} | |
# Keep this line and make sure there is an empty line below this one | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment