Created
June 16, 2018 04:53
-
-
Save jyfcrw/bae265fdec64a68a68686de4d0c4d199 to your computer and use it in GitHub Desktop.
PowerShell Internet Proxy Script
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
<# | |
.Synopsis | |
This function will set the proxy settings provided as input to the cmdlet. | |
.Description | |
This function will set the proxy server. | |
.Parameter ProxyServer | |
This parameter is set as the proxy for the system. | |
Data from. This parameter is Mandatory | |
.Example | |
Set-Proxy -proxy "127.0.0.1:7080" | |
#> | |
Function Set-Proxy | |
{ | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory=$True,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] | |
[String[]]$Proxy | |
) | |
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>' | |
[Environment]::SetEnvironmentVariable('http_proxy', $proxy, 'User') | |
[Environment]::SetEnvironmentVariable('https_proxy', $proxy, 'User') | |
} | |
End | |
{ | |
Write-Output "Proxy is now enabled" | |
Write-Output "Proxy Server : $proxy" | |
} | |
} | |
<# | |
.Synopsis | |
This function will clear the proxy settings provided as input to the cmdlet. | |
.Description | |
This function will clear the proxy server. | |
.Example | |
Clear-Proxy | |
#> | |
Function Clear-Proxy | |
{ | |
Begin | |
{ | |
$regKey="HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" | |
} | |
Process | |
{ | |
Set-ItemProperty -path $regKey ProxyEnable -value 0 | |
Set-ItemProperty -path $regKey ProxyServer -value '' | |
Set-ItemProperty -Path $regKey ProxyOverride -value '' | |
[Environment]::SetEnvironmentVariable('http_proxy', $null, 'User') | |
[Environment]::SetEnvironmentVariable('https_proxy', $null, 'User') | |
} | |
End | |
{ | |
Write-Output "Proxy is now clean" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use profile to automatic import this proxy.ps1 script.
How to add profile: https://technet.microsoft.com/en-us/library/ff461033.aspx
edit Microsoft.PowerShell_profile.ps1