Skip to content

Instantly share code, notes, and snippets.

@PhilMurwin
Created March 16, 2023 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PhilMurwin/01edd06c330e940851ea8d131ce43f92 to your computer and use it in GitHub Desktop.
Save PhilMurwin/01edd06c330e940851ea8d131ce43f92 to your computer and use it in GitHub Desktop.
Powershell New Self Signed Cert
# https://mattou07.net/posts/create-a-self-signed-certificate-for-iis-with-powershell/
# https://www.yaplex.com/how-to-create-a-self-signed-certificate-for-iis-using-powershell/
# https://adamtheautomator.com/new-selfsignedcertificate/
$binding = Read-Host -Prompt 'Enter the site you need a cert for: '
$cert = New-SelfSignedCertificate -DnsName "$binding" -NotAfter (Get-Date).AddMonths(72) -CertStoreLocation "cert:\LocalMachine\My"
Write-Host "Cert [$binding] has been created in the local machine cert store."
Write-Host "Cert will expire in 6 years."
$DestStore = new-object System.Security.Cryptography.X509Certificates.X509Store([System.Security.Cryptography.X509Certificates.StoreName]::Root,"localmachine")
$DestStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
$DestStore.Add($cert)
$DestStore.Close()
Write-Host "Cert [$binding] has been added to the trusted root cert authorities."
Write-Host "Now go bind the cert in IIS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment