Powershell - Set SSL Certificate on https Binding Powershell - Set SSL Certificate on https Binding powershell powershell

Powershell - Set SSL Certificate on https Binding


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


I had the same error as "Chuck D" when using the answer, I found an additional step was required:

The SSL certificate needs to be in the certificate store before binding to adding to an IIS website binding. This can be done in powershell using the following command:

Import-PfxCertificate -FilePath "C:\path to certificate file\certificate.pfx" -CertStoreLocation "Cert:\LocalMachine\My"