首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用powershell创建自签名证书- ./makecert

使用powershell创建自签名证书- ./makecert
EN

Stack Overflow用户
提问于 2017-04-04 06:23:39
回答 1查看 1.5K关注 0票数 2

我使用下面的代码来启用WinRM https侦听器,但是在执行Powershell中的代码时,我得到了以下错误:

.\makecert :术语“.\makecert”不能识别为cmdlet、函数、脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后再试一次。

我试图为cert.exe提供完全限定的路径,但这是行不通的。在提供了完全限定的路径之后,我开始获得以下新错误:

获取-随机:参数不能处理,因为参数名称'e‘是模棱两可的。可能的匹配包括:-ErrorAction -ErrorVariable

完整代码:

代码语言:javascript
复制
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
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-04 08:07:37

代码语言:javascript
复制
$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):

将上述代码更正为:

代码语言:javascript
复制
$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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43199732

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档