Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell IIS7 Snap in Assign SSL certificate to https binding

As part of our automated build procedure we are trashing and reconstructing our IIS site with powershell scripts.

Once i have created the AppPool and the website complete with binding information I want to set the SSL certificate for the https binding. I can't find any concrete examples onl;ine anywhere that demonstrate this.

Any ideas?

Looking for a benevolent powershell god...

like image 627
El Toro Bauldo Avatar asked Apr 13 '10 11:04

El Toro Bauldo


People also ask

How do I add SSL certificates to bindings?

In Internet Information Services (IIS) Manager, under Connections, expand your server's name, expand Sites, and then select the website on which you want to install the SSL Certificate. In the Actions menu, under Edit Site, click Bindings. In the Site Bindings window, click Add.

How do I bind a certificate in IIS using PowerShell?

To enable SSL three steps are involved: Acquiring and installing a certificate. Creating an SSL binding in IIS. Assigning the certificate to the IP:Port of the IIS binding.

How do I set up 443 binding in IIS?

Select your site in the Actions pane, and click Bindings... . Click Add... and select https from the type drop-down list, set the port to 443, If port 443 is listed, select this port from the list and click Edit. Select your certificate name in the SSL certificate drop-down list, and click OK.


2 Answers

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

import-module webadministration
$computerName = $Env:Computername
$domainName = $Env:UserDnsDomain
New-WebBinding -Name "MyWebSite" -IP "*" -Port 443 -Protocol https
Get-ChildItem cert:\LocalMachine\My | where { $_.Subject -match "CN\=$Computername\.$DomainName" } | select -First 1 | New-Item IIS:\SslBindings\0.0.0.0!443
like image 95
isaolmez Avatar answered Oct 05 '22 12:10

isaolmez


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 = 443

Push-Location IIS:\SslBindings

Get-Item cert:\LocalMachine\Root\$thumb | New-Item $IPAddress!$port

Pop-Location

Hope this is of help to anyone

like image 20
El Toro Bauldo Avatar answered Oct 05 '22 11:10

El Toro Bauldo