首先打开 PowerShell【1】, 然后打开 PowerShell 的配置文件:
notepad $profile
如若提示找不到对应文件则先执行下面这个命令创建一个 PowerShell 配置文件:
注意替换里面的 http://example.com 为你的HTTP代理链接
if (!(Test-Path -Path $profile【2】 )) { New-Item -Type File -Path $PROFILE -Force }
然后在打开的文件中添加下列内容:
Microsoft.PowerShell_profile.ps1
$regPath = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings'
function Clear-Proxy
{
Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 0
Set-ItemProperty -Path $regPath -Name ProxyServer -Value ''
Set-ItemProperty -Path $regPath -Name ProxyOverride -Value ''
[Environment]::SetEnvironmentVariable('http_proxy', $null)
[Environment]::SetEnvironmentVariable('https_proxy', $null)
}
function Set-Proxy
{
$proxy = 'http://example.com'
Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 1
Set-ItemProperty -Path $regPath -Name ProxyServer -Value $proxy
Set-ItemProperty -Path $regPath -Name ProxyOverride -Value '<local>'
[Environment]::SetEnvironmentVariable('http_proxy', $proxy)
[Environment]::SetEnvironmentVariable('https_proxy', $proxy)
}
Set-Proxy
最后重启 Windows PowerShell 就可以
如若提示 在此系统上禁止运行脚本 则运行下面这个命令允许运行脚本:
set-executionpolicy remotesigned -scope currentuser

Comments NOTHING