Many online articles suggests using the MakeCert.exe tool available in the Windows SDK for creating a self-signed certificate, but now there is an easier approach available.
New-SelfSignedCertificate-DnsNametest.powershellmagazine.com-CertStoreLocationcert:\LocalMachine\My
Source : PowerShell Magazine » #PSTip Generating a self-signed certificate