我使用下面的代码来启用WinRM https侦听器,但是在执行Powershell中的代码时,我得到了以下错误:
.\makecert :术语“.\makecert”不能识别为cmdlet、函数、脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后再试一次。
我试图为cert.exe提供完全限定的路径,但这是行不通的。在提供了完全限定的路径之后,我开始获得以下新错误:
获取-随机:参数不能处理,因为参数名称'e‘是模棱两可的。可能的匹配包括:-ErrorAction -ErrorVariable
完整代码:
function Configure-WinRMHttpsListener
{
param(
[Parameter(Mandatory = $true)]
[string] $HostName,
[Parameter(Mandatory = $true)]
[string] $port)
# Delete the WinRM Https listener if it is already configured
Delete-WinRMListener
# Create a test certificate
$thumbprint = (Get-ChildItem cert:\LocalMachine\My | Where-Object { $_.Subject -eq "CN=" + $hostname } | Select-Object -Last 1).Thumbprint
if(-not $thumbprint)
{
#$serial = Get-Random
#"C:\Program Files (x86)\Windows Kits\10\bin\x64\makecert.exe" -r -pe -n CN=$hostname -b 01/01/2012 -e 01/01/2022 -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localmachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12 -# $serial
#$thumbprint=(Get-ChildItem cert:\Localmachine\my | Where-Object { $_.Subject -eq "CN=" + $hostname } | Select-Object -Last 1).Thumbprint
#C:\Program Files (x86)\Windows Kits\10\bin\x86\makecert -r -pe -n CN=$hostname -b 01/01/2012 -e 01/01/2022 -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localmachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12
$serial = Get-Random .\makecert -r -pe -n CN=$hostname -b 01/01/2012 -e 01/01/2022 -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localmachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12 -# $serial
$thumbprint=(Get-ChildItem cert:\Localmachine\my | Where-Object { $_.Subject -eq "CN=" + $hostname } | Select-Object -Last 1).Thumbprint
if(-not $thumbprint)
{
throw "Failed to create the test certificate."
}
}
$response = cmd.exe /c .\winrmconf.cmd $hostname $thumbprint
}发布于 2017-04-04 08:07:37
$serial = Get-Random .\makecert -r -pe -n CN=$hostname -b 01/01/2012 -e 01/01/2022 -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localmachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12 -# $serial实际上是两行独立的代码,它们似乎无意中被合并为一行($serial = get-random是第一行)。它们要么需要用分号分隔(在得到随机后),要么作为荧光放在两条单独的线上。您还可能需要使用Makecert.exe的完整路径(或者从它所在的目录运行脚本,但仍然将其引用为.\makecert.exe):
将上述代码更正为:
$serial = Get-Random
& "C:\Program Files (x86)\Windows Kits\10\bin\x64\makecert.exe" -r -pe -n CN=$hostname -b 01/01/2012 -e 01/01/2022 -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localmachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12 -# $serialhttps://stackoverflow.com/questions/43199732
复制相似问题