If the IIS drive is not available, you can use the WebAdministration
module directly. Here’s a script that should help you bind an SSL certificate to a website and update the thumbprint:
# Import the WebAdministration module
Import-Module WebAdministration
# Define variables
$Website = "YourWebsiteName"
$Protocol = "https"
$Port = 443
$IPAddress = "*"
$HostName = "yourhostname.com"
$SNIFlag = 1
$certThumbprint = "YourCertificateThumbprint"
$certStoreLocation = "Cert:\LocalMachine\My"
# Create a new binding
New-WebBinding -Name $Website -Protocol $Protocol -Port $Port -IPAddress $IPAddress -HostHeader $HostName -SslFlags $SNIFlag
# Get the binding
$binding = Get-WebBinding -Name $Website -Protocol $Protocol -Port $Port -IPAddress $IPAddress
# Update the certificate thumbprint
$bindingItem = Get-Item "IIS:\SslBindings\*$($Port)!$($HostName)"
Set-ItemProperty -Path $bindingItem.PSPath -Name CertificateThumbprint -Value $certThumbprint
If you need to update the thumbprint of an existing binding, you can use the following approach:
# Import the WebAdministration module
Import-Module WebAdministration
# Define variables
$Website = "YourWebsiteName"
$Port = 443
$certThumbprint = "NewCertificateThumbprint"
# Get the site
$site = Get-Item "IIS:\Sites\$Website"
# Get the binding
$binding = $site.Bindings.Collection | Where-Object { $_.protocol -eq 'https' -and $_.bindingInformation -eq "*:$Port:" }
# Update the certificate thumbprint
$binding.AddSslCertificate($certThumbprint, "My")
The deserialization issue you’re encountering might be due to the way PowerShell handles objects when remoting. Ensure that you’re running these scripts locally on the server where IIS is installed to avoid deserialization problems.
Let me know if this helps resolve your issue!