Situation - I'm trying to set up website to be used with IIS 10 (development machine, Windows 10) with SSL. Pretty common stuff - certificate (with roots) already registered in WebHosting branch, site created. And then, I'm trying to create binding for HTTPS:
$hostname="mysite.domain.com"
$iisSite="mysite"
$cert = (Get-ChildItem "cert:\LocalMachine\WebHosting" `
| where-object { $_.Subject -like "*domain.com*" } `
| Select-Object -First 1).Thumbprint
# ...
$binding = New-WebBinding -name $iisSite -Protocol https -HostHeader $hostname -Port 443 -SslFlags 1
$binding.AddSslCertificate($cert, "WebHosting")
Binding is created properly, all properties look as expected, except for SSL certificate - none selected, while I can clearly see the one I've been looking for on the list...
I've been googling already about this and everyone says it works on Win server. But somewhat not on my/our dev machine(s)... I do not have access to the win server at the moment to see how it behaves there.
(Note - $cert is found properly, it is created for "*domain.com").
Any suggestions? Or this is just a plain bug? Something else that works? Or I did something wrong?
Ok, this works:
New-WebBinding -name $iisSite -Protocol https -HostHeader $hostname -Port 443 -SslFlags 1
$binding = Get-WebBinding -Name $iisSite -Protocol https  
if ($binding) {
    $binding.AddSslCertificate($cert, "WebHosting")
}
Ech.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With