为什么Powershell ps1文件中出现netsh http add sslcert抛出错误?
我试图从powershell ps1文件中使用netsh http添加sslcert,但它不断抛出错误:为什么Powershell ps1文件中出现netsh http add sslcert抛出错误?,http,powershell,ssl-certificate,guid,netsh,Http,Powershell,Ssl Certificate,Guid,Netsh,我试图从powershell ps1文件中使用netsh http添加sslcert,但它不断抛出错误: $guid = [guid]::NewGuid() netsh http add sslcert ipport=0.0.0.0:443 certhash=5758B8D8248AA8B4E91DAA46F069CC1C39ABA718 appid={$guid} 'JABnAHUAaQBkAA' is not a valid argument for this command. T
$guid = [guid]::NewGuid()
netsh http add sslcert ipport=0.0.0.0:443 certhash=5758B8D8248AA8B4E91DAA46F069CC1C39ABA718 appid={$guid}
'JABnAHUAaQBkAA' is not a valid argument for this command.
The syntax supplied for this command is not valid. Check help for the correct syntax.
Usage: add sslcert [ipport=]<IP Address:port>
[certhash=]<string>
[appid=]<GUID>
[[certstorename=]<string>
[verifyclientcertrevocation=]enable|disable
[verifyrevocationwithcachedclientcertonly=]enable|disable
[usagecheck=]enable|disable
[revocationfreshnesstime=]<u-int>
[urlretrievaltimeout=]<u-int>
[sslctlidentifier=]<string>
[sslctlstorename=]<string>
[dsmapperusage=]enable|disable
[clientcertnegotiation=]enable|disable]
我可能错了,但我相信这与我如何在powershell脚本文件中指定appid GUID有关。有人能帮我解决这个错误吗?这是Powershell解析cmd命令的方式有问题。 这将成功执行命令:
$guid = [guid]::NewGuid()
$Command = "http add sslcert ipport=0.0.0.0:443 certhash=5758B8D8248AA8B4E91DAA46F069CC1C39ABA718 appid={$guid}"
$Command | netsh
下面的代码将起作用,
&
此处用于调用带有参数的程序,并且“appid={$guid}”
使其传递字符串值
& netsh http add sslcert ipport=0.0.0.0:443 certhash=5758B8D8248AA8B4E91DAA46F069CC1C39ABA718 "appid={$guid}"
出现错误的原因是,必须用倒勾(`)转义大括号 以下命令将从PowerShell命令行运行: 这将通过PowerShell命令行工作:
$AppId = [Guid]::NewGuid().Guid
$Hash = "209966E2BEDA57E3DB74FD4B1E7266F43EB7B56D"
netsh http add sslcert ipport=0.0.0.0:8000 certhash=$Hash appid=`{$Guid`}
重要的细节是用倒勾(`)转义每个{}
如果netsh出现错误,请尝试将certstorename追加到my
不需要使用变量。这只是为了方便
$AppId = [Guid]::NewGuid().Guid
$Hash = "209966E2BEDA57E3DB74FD4B1E7266F43EB7B56D"
netsh http add sslcert ipport=0.0.0.0:8000 certhash=$Hash appid=`{$Guid`}