Skip to content

Instantly share code, notes, and snippets.

@andrx
Created October 27, 2016 19:23
Show Gist options
  • Save andrx/9c79799878bb52f53afd41cd92004551 to your computer and use it in GitHub Desktop.
Save andrx/9c79799878bb52f53afd41cd92004551 to your computer and use it in GitHub Desktop.
Update SSL certificate for IIS Website binding
dir cert:\localmachine\my
''
'Get the certificate''s Thumbprint'
Pause
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