Wednesday, August 3, 2016

Create Test SSL Certificate for IIS With PowerShell and Windows 2012 R2

In order to create an SSL Certificate for test purpose you can bind to a web site in IIS, you do not need anymore certutil or makecert.

Windows 2012 R2 PowerShell has a commandlet you can use for this purpose.

This simple command, for example, create a SSL Cert using 2048 key lenght and valid for 5 years.

New-SelfSignedCertificate -KeyLength 2048 -NotAfter (Get-Date).AddYears(5) -certstorelocation "cert:\localmachine\my" -dnsname youfqdnwebappname

This cert will be stored in "localmachine\my" and can be used in IIS binding.

You can find more info and parameters here:

https://technet.microsoft.com/en-US/library/hh848633.aspx

Pay attention that the same command on Windows 2012 (not R2 version) do not have the same parameters. For example you cannot use -NotAfter parameter. This means that you certificate will have a validity of only one year (that one is the default).