How to create a self-signed certificate with PowerShell

When we develop web-application or experiment with some technologies it’s quite common to need a certificate. A certificate for real world scenarios can be expensive and it’s over-engineering for testing purposes. So with this simple PowerShell script (on Windows) we can create a self-signed certificate for development enviroments.

$cert = New-SelfSignedCertificate -DnsName mydemowebapp.net -CertStoreLocation cert:\LocalMachine\My

$pwd = ConvertTo-SecureString -String "MyPassword" -Force -AsPlainText

Export-PfxCertificate -Cert $cert -FilePath C:\temp\cert.pfx -Password $pwd

With these few line of codes we create and store a self-signed certificate in the Windows Certificate Store. With the last line (Export-PfxCertificate) we export the certificate for furher use for example to do some experiments with cloud providers.

Reference

GitHub Gist

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.