Run the New-SelfSignedCertificate
cmdlet as shown below to add a certificate to the local store on PC, replacing testcert.petri.com
with the full qualified domain name(FQDN) that you‘d like to see.
> $cert = New-SelfSignedCertificate -certstorelocation cert:\localmachine\my -dnsname testcert.petri.com
The next step is to export a self-signed certificate.
> $pwd = ConvertTo-SecureString -String ‘passw0rd!’ -Force -AsPlainText
Now we can export a self-signed certificate using Export-PfxCertificate
cmdlet. Use the password($pwd
) created above, and create an additional string($path
), which specifies the path to the certificate created with New-SelfSignedCertificate
cmdlet.
> $path = ‘cert:\localMachine\my\‘ + $cert.thumbprint Export-PfxCertificate -cert $path -FilePath c:\temp\cert.pfx -Password $pwd
NOTE: the
c:\temp
directory, or whatever the directory you specify in the-FilePath
parameter, must already existed.