You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell内联脚本GetProxy引号问题:无需单引号如何运行?

解决内联PowerShell脚本中双引号包裹GetProxy参数的执行问题

这个问题本质是cmd与PowerShell的引号解析规则冲突导致的:当你在cmd里直接执行powershell.exe命令时,双引号会被cmd优先解析,而不是完整传递给PowerShell,进而造成GetProxy的参数被错误截断或解析。下面是几个不用单引号包裹GetProxy参数的可行方案:

方案1:用cmd的反斜杠转义双引号

在cmd环境中,反斜杠\是双引号的转义符,添加后cmd会把双引号当作普通字符传递给PowerShell:

c:\>powershell.exe IEX(Invoke-WebRequest http://example.com/example.html -ProxyUseDefaultCredentials -Proxy $([System.Net.WebRequest]::GetSystemWebProxy().GetProxy(\"http://example.com/\").Absoluteuri))

方案2:用PowerShell的反引号转义(需双重转义)

PowerShell原生用反引号`作为转义符,但在cmd里直接使用的话,cmd会吃掉单个反引号,所以需要写两个反引号让PowerShell最终收到一个:

c:\>powershell.exe IEX(Invoke-WebRequest http://example.com/example.html -ProxyUseDefaultCredentials -Proxy $([System.Net.WebRequest]::GetSystemWebProxy().GetProxy(``"http://example.com/``").Absoluteuri))

方案3:将整个PowerShell命令用单引号包裹

把完整的PowerShell脚本用单引号括起来,cmd会将单引号内的内容完整传递给PowerShell,内部的双引号就不会被cmd干扰:

c:\>powershell.exe 'IEX(Invoke-WebRequest http://example.com/example.html -ProxyUseDefaultCredentials -Proxy $([System.Net.WebRequest]::GetSystemWebProxy().GetProxy("http://example.com/").Absoluteuri))'

内容的提问来源于stack exchange,提问作者Noname

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:02:50