Created
March 16, 2023 17:26
-
-
Save PhilMurwin/01edd06c330e940851ea8d131ce43f92 to your computer and use it in GitHub Desktop.
Powershell New Self Signed Cert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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