我用下面的代碼實現的WinRM HTTPS偵聽器,但在執行中PowerShell中的代碼,我收到以下錯誤:創建自簽名證書 - ./makecert使用PowerShell
.\makecert : The term '.\makecert' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
我試着提供cert.exe的完全限定路徑,但這不起作用。提供完全合格的路徑後,我開始了以下新的錯誤:
Get-Random : Parameter cannot be processed because the parameter name 'e' is ambiguous. Possible matches include: -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
}
'$ 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我的-sr localmachine -sky交換-sp「Microsoft RSA SChannel加密提供程序」-sy 12 - #$ serial「您如何期待這起作用? – 4c74356b41
爲什麼不使用本機powershell cmdlet?新SelfSignedCertificate? – bluuf