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.

How to create a Self-Signed Certificate using Powershell

上一篇:在 Linux 系统中如何管理 systemd 服务


下一篇:(二)进程间通信方式