Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New-SelfSignedCertificate -CertStoreLocation cannot find path

Using the New-SelfSignedCertificate cmdlet, I want to specify the location on my harddrive as C:\Development\My Project. This command:

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

gives this error:

Cannot find path 'Cert:\LocalMachine\Development\My Project' because it does not exist.

How do I do this?

$PSVersionTable.PSVersion
Major  Minor  Build  Revision
-----  -----  -----  --------
5      0      10586  962
like image 553
Al Lelopath Avatar asked Jan 03 '23 19:01

Al Lelopath


2 Answers

The path that you specify for New-SelfSignedCertificate -CertStoreLocation is a certificate store, not a file path. What you will most likely want to do is specify cert:\LocalMachine\my which will create the certificate in your personal store, and then export that certificate to a file on the hard drive if you need it in file form. Something like this should work for that:

$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
like image 142
TheMadTechnician Avatar answered Jan 06 '23 08:01

TheMadTechnician


I got this error when I had an undefined execution policy for the CurrentUser scope.

Get-ExecutionPolicy -List

If it's undefined, set it to RemoteSigned with this command

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
like image 35
Logan Avatar answered Jan 06 '23 08:01

Logan