在PowerShell上使用netsh失败并显示错误:参数不正确

rae*_*ae1 5 powershell ssl cmd ssl-certificate netsh

我一直在尝试在PowerShell上运行以下命令:

    netsh http add sslcert ipport=0.0.0.0:443 certhash=<some certhash> appid={<random guid>}
Run Code Online (Sandbox Code Playgroud)

问题是,它"The parameter is incorrect"每次都会返回.我检查了证书哈希号码和生成的guid,他们都没问题.实际上,我运行了相同的命令cmd.exe并且它工作得很好,这增加了挫败感.

我想将变量作为certhash和传递appid,这就是我使用PowerShell的原因.

如果有人可以帮助我理解为什么它不起作用或者是否有缺少它可以在PowerShell上工作.

rae*_*ae1 14

我终于知道了问题所在:虽然在PowerShell中你可以cmd本机执行命令,但是命令的解析会稍微改变,在这种情况下它会破坏appid参数的解释(那些大括号!).

为了解决这个问题,我只是将括号({})<random guid>括在单引号中,因此,

    netsh http add sslcert ipport=0.0.0.0:443 certhash=<certhash> appid='{<random guid>}'
Run Code Online (Sandbox Code Playgroud)

而不是(注意缺少的'引号'),

    netsh http add sslcert ipport=0.0.0.0:443 certhash=<certhash> appid={<random guid>}
Run Code Online (Sandbox Code Playgroud)

并且命令完美无缺.

有关PowerShell解析的更多信息,请参阅了解PowerShell解析模式.