【发布时间】:2017-04-04 16:30:16
【问题描述】:
我正在使用下面的代码来启用 WinRM https 侦听器,但是在 Powershell 中执行代码时,我收到以下错误:
.\makecert : 术语 '.\makecert' 未被识别为 cmdlet、函数、脚本文件或可运行的程序。检查拼写 的名称,或者如果包含路径,请验证该路径是 正确并重试。
我尝试提供 cert.exe 的完全限定路径,但这不起作用。提供完全限定路径后,我开始收到以下新错误:
Get-Random : 参数无法处理,因为参数名称 'e' 是模棱两可的。可能的匹配项包括:-ErrorAction -错误变量
完整代码:
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
}
【问题讨论】:
-
$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你认为这会如何工作? -
为什么不使用本机 powershell cmdlet 呢?新自签名证书?
标签: powershell