Skip to content

Instantly share code, notes, and snippets.

@craig-martin
Created January 29, 2016 18:39
Show Gist options
  • Save craig-martin/4e5edfbb85c48011f0ae to your computer and use it in GitHub Desktop.
Save craig-martin/4e5edfbb85c48011f0ae to your computer and use it in GitHub Desktop.
Create a Self-Signed Cert with PowerShell
#Create the cert
New-SelfSignedCertificate -DnsName 'foo.azurewebsites.net' -CertStoreLocation cert:\CurrentUser\My -KeyAlgorithm RSA -KeyLength 2048 -KeyExportPolicy Exportable #-KeyUsage DigitalSignature,nonRepudiation,keyEncipherment
#Look for the cert
dir Cert:\CurrentUser\My
#Export the cert to a PFX file
$mypwd = ConvertTo-SecureString -String "WhoFedTheDogCorn?" -Force –AsPlainText
dir Cert:\CurrentUser\My | Where Subject -EQ 'CN=foo.azurewebsites.net' | Export-PfxCertificate -ChainOption BuildChain -Password $mypwd -FilePath E:\Scratch\fooCert.pfx
#Clean-up: Remove the cert from the certificate store
dir Cert:\CurrentUser\My | Where Subject -EQ 'CN=microsoft-apiappf710aa4ba6b148fa8de060cd4ac32edf.azurewebsites.net' | Remove-Item
#Clean-up: Remove the PFX file
dir E:\Scratch\fooCert.pfx | Remove-Item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment