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?
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.
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.
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")
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