1. 首先以管理员模式打开PowerShell
  2. 输入code $PROFILE
  3. 在打开的文本编辑器中创建下列函数:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function proxy {
param(
[string]$proxyAddress = "http://localhost:10809"
)
$env:http_proxy = $proxyAddress
$env:https_proxy = $proxyAddress
Write-Host "Proxy set to $proxyAddress"
}

function unproxy {
Remove-Item Env:http_proxy
Remove-Item Env:https_proxy
Write-Host "Proxy settings cleared."
}

其中proxyAddress指向的IP和端口为运行代理软件的设备IP和软件开放的代理端口

  1. 保存并关闭文本编辑器,重新启动PowerShell
  2. 现在可以通过直接输入执行proxyunproxy来启动或关闭代理了。