diff --git a/templates/create-certificate-binding.ps1.erb b/templates/create-certificate-binding.ps1.erb index 28ac89e..64dc764 100644 --- a/templates/create-certificate-binding.ps1.erb +++ b/templates/create-certificate-binding.ps1.erb @@ -5,10 +5,17 @@ $certsAttachedToSite = Get-ChildItem IIS:\SSLBindings | ? { $site | Select-Objec $certificate = Get-ChildItem CERT:\LocalMachine\My | ? { $certsAttachedToSite -contains $_.Thumbprint} | Where-Object { $_.Thumbprint -eq "<%= certificate_thumbprint %>" } if((Test-Path IIS:\SslBindings\$ip!$port) -eq $false) { + push-location IIS:\SslBindings Get-Item Cert:\LocalMachine\My\<%= certificate_thumbprint %> | New-Item <%= ip_address %>!443 } -elseif (($certificate -ne $null) -and ($certificate.Thumbprint -ne "") { +elseif (((Test-Path IIS:\SslBindings\$ip!$port) -eq $true) -and (($certificate -ne $null) -or ($certificate.Thumbprint -ne <%= certificate_thumbprint %>))) { + push-location IIS:\SslBindings Get-Item Cert:\LocalMachine\My\<%= certificate_thumbprint %> | Set-Item <%= ip_address %>!<%= port %> + foreach ($cert in $certificates) { + if(($cert -ne $null) -and ($cert.Thumbprint -ne "<%= certificate_thumbprint %>")) { + Get-Item Cert:\LocalMachine\My\$cert.Thumbprint | Remove-Item <%= ip_address %>!<%= port %> + } + } } else { exit 0