New-SelfSignedCertificate -CertStoreLocation无法找到路径

时间:2017-06-26 15:19:59

标签: powershell certificate

使用New-SelfSignedCertificate cmdlet,我想将硬盘驱动器上的位置指定为 C:\ Development \ My Project 。这个命令:

New-SelfSignedCertificate -CertStoreLocation "cert:\LocalMachine\Development\My Project" 

给出了这个错误:

  

无法找到路径' Cert:\ LocalMachine \ Development \ My Project'因为   它不存在。

我该怎么做?

$PSVersionTable.PSVersion
Major  Minor  Build  Revision
-----  -----  -----  --------
5      0      10586  962

2 个答案:

答案 0 :(得分:4)

您为New-SelfSignedCertificate -CertStoreLocation指定的路径是证书存储,而不是文件路径。您最有可能要做的是指定cert:\LocalMachine\my,它将在您的个人存储中创建证书,然后将该证书导出到硬盘驱动器上的文件(如果您需要文件格式)。这样的事情应该适用于此:

$notAfter = [datetime]::Today.AddYears(2)
$thumb = (New-SelfSignedCertificate -CertStoreLocation cert:\localmachine\my -DnsName $env:USERDNSDOMAIN -KeyExportPolicy Exportable -Provider "Microsoft Enhanced RSA and AES Cryptographic Provider" -NotAfter $notAfter).Thumbprint
$pwd = 'SuperS3cret!'
$SSpwd = ConvertTo-SecureString -String $pwd -Force -AsPlainText
Export-PfxCertificate -cert "cert:\localmachine\my\$thumb" -FilePath "C:\Development\My Project\MyDevCert.pfx" -Password $SSpwd

答案 1 :(得分:1)

当我对 CurrentUser 范围有一个未定义的执行策略时,我收到了这个错误。

Get-ExecutionPolicy -List

如果未定义,请使用此命令将其设置为 RemoteSigned

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser