Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell - Set SSL Certificate on https Binding

I am trying to use PowerShell to set the SSL certificate on an IIS site for a self signed/local certificate.

I create the certificate:

$newCert =         New-SelfSignedCertificate         -DnsName www.mywebsite.ru         -CertStoreLocation cert:\LocalMachine\My 

Then try to set the SSL bindings:

get-item        cert:\LocalMachine\MY\$newCert.Thumbprint |        new-item -path IIS:\SslBindings\0.0.0.0!443 

as shown on this post: http://www.iis.net/learn/manage/powershell/powershell-snap-in-configuring-ssl-with-the-iis-powershell-snap-in

also shown here: Powershell IIS7 Snap in Assign SSL certificate to https binding

I also tried:

get-item        cert:\LocalMachine\MY\$newCert.Thumbprint |        new-item -path IIS:\SslBindings\*!443 

To no avail, I'm not seeing the SSL Certificate set in the Edit Site Binding dialog.

Any thoughts?

like image 851
Kent Fehribach Avatar asked Sep 04 '15 04:09

Kent Fehribach


People also ask

How do I add an SSL certificate to PowerShell using IIS?

First, check that IIS exists on the server. Then, connect to the Windows Server 2016 machine using PowerShell remoting. Use the Get-Website command to see if there are any existing websites to make sure you can enumerate the existing sites later. The example below shows a website called Default Web Site.

How do I bind an SSL certificate?

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, select binding for https and then, click Edit.


1 Answers

You have to assign the certifcate to a specific site.

You can retrieve the binding information of your site using the Get-WebBinding cmdlet and set the SSL Certificate using the AddSslCertificate function:

$siteName = 'mywebsite' $dnsName = 'www.mywebsite.ru'  # create the ssl certificate $newCert = New-SelfSignedCertificate -DnsName $dnsName -CertStoreLocation cert:\LocalMachine\My  # get the web binding of the site $binding = Get-WebBinding -Name $siteName -Protocol "https"  # set the ssl certificate $binding.AddSslCertificate($newCert.GetCertHashString(), "my") 
like image 51
Martin Brandl Avatar answered Sep 17 '22 04:09

Martin Brandl