Powershell IIS7 Snap in Assign SSL certificate to https binding Powershell IIS7 Snap in Assign SSL certificate to https binding powershell powershell

Powershell IIS7 Snap in Assign SSL certificate to https binding


You can merge previous examples with creation of an https binding in a web site.

import-module webadministration$computerName = $Env:Computername$domainName = $Env:UserDnsDomainNew-WebBinding -Name "MyWebSite" -IP "*" -Port 443 -Protocol httpsGet-ChildItem cert:\LocalMachine\My | where { $_.Subject -match "CN\=$Computername\.$DomainName" } | select -First 1 | New-Item IIS:\SslBindings\0.0.0.0!443


Here is how to do it simply:

First identify thecertificate that you want to assign and obtain it's thumbprint

e.g. Your certificate might be in cert:\LocalMachine\Root

You can obtain the thumbprint with the following:

$thumb = (Get-ChildItem cert:\LocalMachine\Root | where-object { $_.Subject -like "YOUR STRING HERE*" } | Select-Object -First 1).Thumbprint

<<< Now one can assign the certificate to an ip address and port comme ci >>>

$IPAddress = 101.100.1.90$port = 443Push-Location IIS:\SslBindingsGet-Item cert:\LocalMachine\Root\$thumb | New-Item $IPAddress!$portPop-Location

Hope this is of help to anyone


You can make the script simpler like this:

Get-ChildItem cert:\LocalMachine\Root | where { $_.Subject -like "YOUR STRING HERE*" } | select -First 1 | New-Item IIS:\SslBindings\0.0.0.0!443

Use 0.0.0.0 to target all hosted IP's (equivalent to "*" in IIS Manager) or replace it with a specific IP if needed.