New-SelfSignedCertificate -CertStoreLocation找不到路径

Al *_*ath 1 powershell certificate

使用New-SelfSignedCertificate cmdlet,我要将硬盘上的位置指定为C:\ Development \ My Project。该命令:

New-SelfSignedCertificate -CertStoreLocation "cert:\LocalMachine\Development\My Project" 
Run Code Online (Sandbox Code Playgroud)

给出此错误:

找不到路径“证书:\ LocalMachine \ Development \ My Project”,因为它不存在。

我该怎么做呢?

$PSVersionTable.PSVersion
Major  Minor  Build  Revision
-----  -----  -----  --------
5      0      10586  962
Run Code Online (Sandbox Code Playgroud)

The*_*ian 5

您指定的路径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
Run Code Online (Sandbox Code Playgroud)