Skip to content

Instantly share code, notes, and snippets.

@gschizas
Created July 20, 2016 22:10
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gschizas/def013639d1fc271011016661f64673b to your computer and use it in GitHub Desktop.
Save gschizas/def013639d1fc271011016661f64673b to your computer and use it in GitHub Desktop.
Import-Module WebAdministration
# Get the latest certificate in store that applies to my site
$cert = (Get-ChildItem Cert:\LocalMachine\My |
Where-Object {$_.Subject.Contains('*.example.com')} |
Sort-Object -Descending {[System.DateTime]::Parse($_.GetExpirationDateString())} |
Select-Object -First 1)
Set-Location IIS:\Sites
# Get all sites
Get-WebConfiguration -Filter "/system.applicationHost/sites/site[contains(@name, '.example.com')]/bindings/binding[@protocol='https']" |
Where-Object {$_.certificateHash -ne $cert.Thumbprint} |
% {
Write-Host $_
$_.RemoveSslCertificate()
$_.AddSslCertificate($cert.Thumbprint, 'My')
}
@LauraE1967
Copy link

LauraE1967 commented Jan 26, 2023

Oh my gosh!! This has saved me hours and headache. I have been searching online and using the commands from several different sites, everyone failed at some point. This one works! Thank you...Thank you!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment