Great article. I have been working on finding a solution to add a certificate to a remote machine using Ssh to connect, only to run into a variety of issues.
I see, understand and successfully added the certificate to the cert store and create the new web-binding. However, I am having problems binding the website to the certificate through PowerShell. I've attempted to use the AddSslCertificate method after using Get-WebBinding, but you run into a deserializing issue over HTML.
I have tried using the IIS drive, but I have run into places where machines don't have the IIS drive available (A drive with the name 'IIS' does not exist.)
Is there an "IIS" cmdlet that can bind the certificate to the website and/or update the thumbprint in the event of replacing the certificate. I feel You might be missing that part of securing wesbites.
Here are a couple samples of my code - I'd love to get some ideas.
* Using IIS Drive (Not all machines have drive available)
New-WebBinding -Name $Website -Protocol $Protocol -Port $Port -IPAddress $IPAddress -HostHeader $HostName -SslFlags $SNIFlag
$bindingItem = Get-Item "IIS:\SslBindings\*$($Port)!$($HostName)"
Set-ItemProperty -Path $bindingItem.PSPath -Name CertificateThumbprint -Value $cert.Thumbprint
* This code failed because of this error: Method invocation failed because [Deserialized.Microsoft.IIs.PowerShell.Framework.ConfigurationEle
ment#bindings#binding] does not contain a method named 'AddSslCertificate'.
New-WebBinding -Name $Website -Protocol $Protocol -Port $Port -IPAddress $IPAddress -HostHeader $HostName -SslFlags $SNIFlag
$NewBinding = Get-WebBinding -Name $Website -Protocol $Protocol -Port $port -IPAddress $IPAddress
$NewBinding.AddSslCertificate($Certificate.Thumbprint, $StorePath)
Any thoughts are appreciated to overcome my binding issues.