Created
October 27, 2016 19:23
-
-
Save andrx/9c79799878bb52f53afd41cd92004551 to your computer and use it in GitHub Desktop.
Update SSL certificate for IIS Website binding
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
dir cert:\localmachine\my | |
'' | |
'Get the certificate''s Thumbprint' | |
Pause |
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
function UpdateWebsiteBindingCertificate { | |
Param( | |
[string] $sitename, | |
[string] $sslThumbprint | |
); | |
import-module webadministration; | |
$wsbindings = (Get-ItemProperty -Path "IIS:\Sites\$sitename" -Name Bindings) | |
for($i=0;$i -lt ($wsbindings.Collection).length;$i++){ | |
if((($wsbindings.Collection[$i]).bindingInformation).Contains("*:443")){ | |
$item = $($wsbindings.Collection[$i].bindingInformation.replace(':', '!')) | |
Write-Output "Deleting old binding: $($item)" | |
Get-Item "IIS:\SslBindings\$($wsbindings.Collection[$i].bindingInformation.replace(':', '!'))" | remove-item | |
Write-Output "Setting SSL certificate for new binding: $($item)" | |
New-Item -Path "IIS:\SslBindings\$($item)" -Thumbprint $sslThumbprint -SSLFlags 1 | |
Write-Output "" | |
} | |
} | |
} | |
UpdateWebsiteBindingCertificate "RewardsPortal" "01B7202156ABECB2A1F7C3590AB52FCDCFB53F1" | |
Pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment