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
-DnsName
test.powershellmagazine.com
-CertStoreLocation
cert:\LocalMachine\My
Source : PowerShell Magazine » #PSTip Generating a self-signed certificate