Created
July 20, 2016 22:10
-
-
Save gschizas/def013639d1fc271011016661f64673b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!!!