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
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With