Create a Self-Signed Certificate in Windows Using PowerShell ⚡ | 2-Minute Guide

Опубликовано: 24 Апрель 2026
на канале: The Journey of DevOps
2,782
34

Step-by-step PowerShell commands with explanations.
Generate the Certificate –​
$cert = New-SelfSignedCertificate -DnsName "test.com" -CertStoreLocation "cert:\LocalMachine\My"​

$cert – Variable to store the value​
New-SelfSignedCertificate – PowerShell command​
-DnsName – Certificate Name​
CertStoreLocation - certificate store (This cannot be file path)
Export the Certificate –​
Export-PfxCertificate -Cert $cert -FilePath "D:\test\certificate.pfx" -Password (ConvertTo-SecureString -String "password" -Force -AsPlainText)​

Export-PfxCertificate - PowerShell command​
-Cert – Certificate Location​
-FilePath – where you want to export the certificate​
-Password – Password for .pfx file

Export the Private Key–​
openssl pkcs12 -in "D:\test\certificate.pfx" -nocerts -out "D:\test\privateKey.pem" -nodes -passin pass:password​

-in - Specifies the input .pfx file.​
-nocerts - Tells OpenSSL to only extract the private key, without the certificate.​
-out - Specifies the output file for the private key.​
-nodes - Ensures that the private key is not encrypted.​
-passin – Provide the export password.

Export the Certificate –​

openssl pkcs12 -in "D:\test\certificate.pfx" -clcerts -nokeys -out "D:\test\certificate.pem"-passin pass:password​

-in - Specifies the input .pfx file.​
clcerts option tells OpenSSL to only output the client certificate.​
-nokeys - Tells OpenSSL to only extract the certificate, without the private key.​
-out - Specifies the output file for the PEM file.​
-passin – Provide the export password.

Convert PEM to CRT Format–​

openssl x509 -outform der -in "D:\test\certificate.pem" -out "D:\test\certificate.crt"

#PowerShell
#SelfSignedCertificate
#SSLCertificate
#HTTPS
#CyberSecurity
#WindowsSecurity
#DevOps
#PowerShellScript
#Automation
#ITSecurity
#PKI
#Encryption
#SSL
#TLS
#NetworkSecurity
#WebSecurity
#SSLSetup
#CertificateAuthority
#WindowsAdmin
#TechTutorial