使用 PowerShell Profile
powershell
# 检查是否存在 profile
Test-Path $PROFILE
# 如果不存在则创建
New-Item -Type File -Path $PROFILE -Force
编辑 Profile 文件
powershell
notepad $PROFILE
在文件中添加函数
#powershell
function Start-Proxy {
$Env:http_proxy="http://192.168.21.111:7890"
$Env:https_proxy="http://192.168.21.111:7890"
}
function Stop-Proxy {
set HTTP_PROXY=
set HTTPS_PROXY=
}
function Show-Proxy {
Write-Output "Current proxy settings:"
netsh winhttp show proxy
}
# 设置别名
Set-Alias startproxy1 Start-Proxy
Set-Alias stopproxy1 Stop-Proxy
Set-Alias proxystatus Show-Proxy
重新加载 Profile
powershell
. $PROFILE
注意这是在powershell里面是这样设置的,使用是在powershell里面使用
如果在cmd环境下添加一个bat文件到有环境变量可以识别的目录就可以
比如添加一个startproxy.bat,使用的时候在cmd下startproxy就可以了
set HTTP_PROXY=http://192.168.21.111:7890
set HTTPS_PROXY=http://192.168.21.111:7890