powershell 配置终端代理函数proxy
2025年1月9日
首先,我们需要找到 PowerShell 的配置文件。如果你还没有创建过,可以用以下命令创建:
if (!(Test-Path -Path $PROFILE)) { New-Item -ItemType File -Path $PROFILE -Force }
打开文件编辑
notepad $PROFILE
这会打开你的 PowerShell 配置文件。配置文件的默认路径通常是: C:\\Users\\你的用户名\\Documents\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1
function proxy {
$env:http_proxy = "<http://127.0.0.1:10808>"
$env:https_proxy = "<http://127.0.0.1:10808>"
[System.Net.WebRequest]::DefaultWebProxy = New-Object System.Net.WebProxy("<http://127.0.0.1:10808>")
Write-Host "Proxy enabled: <http://127.0.0.1:10808>" -ForegroundColor Green
}
function unproxy {
$env:http_proxy = $null
$env:https_proxy = $null
[System.Net.WebRequest]::DefaultWebProxy = $null
Write-Host "Proxy disabled" -ForegroundColor Yellow
}
function check-proxy {
if ($env:http_proxy-or $env:https_proxy) {
Write-Host "Current proxy settings:" -ForegroundColor Cyan
Write-Host "HTTP Proxy: $env:http_proxy"
Write-Host "HTTPS Proxy: $env:https_proxy"
}else {
Write-Host "No proxy is currently set." -ForegroundColor Cyan
}
}