How to create a Self-Signed Certificate using Powershell

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.

猜你喜欢

转载自www.cnblogs.com/matt1985/p/12977897.html