powershell script to create self signed certificate

Automation How To Powershell Website

powershell script to create self signed certificate

Problem -> Sometime while performing any application test or configuring test environment it is difficult to buy certificate so better option is to use self sigh certificate.

There are multiple ways to generate self sign certificate, Prior to PowerShell 4.0, you needed to download MakeCert.exe or another utility to create self signed certificates. Obtaining MakeCert involved jumping through a number of hoops, but now microsoft included command in powershell 4.0 which have direct command to get self sign certificate.


Solution 1 ->

The commands you need are New-SelfSignedCertificate. The way you use them is as follows.

First – you need the FQDN that you want to use for the certificate. For example-  app.arunsabale.westindia.cloudapp.azure.com . You then use below command and you will get self sign cert in “localmachine\my” store…


New-SelfSignedCertificate -certstorelocation cert:\localmachine\my -dnsname  app.arunsabale.westindia.cloudapp.azure.com


Solution 2 -> if you dont have ps 4.0 and New-SelfSignedCertificate command then you can still use self sign certificate generator  NewSelfsignedCertificateEx on –https://gallery.technet.microsoft.com/scriptcenter/Self-signed-certificate-5920a7c6

Ex –

New-SelfsignedCertificateEx -Subject "CN=Test Code Signing" -EKU "Code Signing" -KeySpec "Signature" ` 
-KeyUsage "DigitalSignature" -FriendlyName "Test code signing" -NotAfter $([datetime]::now.AddYears(5))

(Visited 4 times, 1 visits today)

Comments are closed.