[英]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.我正在尝试使用 PowerShell 在 IIS 站点上为自签名\/本地证书设置 SSL 证书。
I create the certificate:我创建证书:
$newCert =
New-SelfSignedCertificate
-DnsName www.mywebsite.ru
-CertStoreLocation cert:\LocalMachine\My
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:您可以使用Get-WebBinding cmdlet 检索站点的绑定信息,并使用
AddSslCertificate
函数设置 SSL 证书:
$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:我在使用答案时遇到了与“Chuck D”相同的错误,我发现需要一个额外的步骤:
The SSL certificate needs to be in the certificate store before binding to adding to an IIS website binding.在绑定到添加到 IIS 网站绑定之前,SSL 证书需要在证书存储中。 This can be done in powershell using the following command:
这可以使用以下命令在 powershell 中完成:
Import-PfxCertificate -FilePath "C:\path to certificate file\certificate.pfx" -CertStoreLocation "Cert:\LocalMachine\My"
The AddSslCertificate method not available everywhere. AddSslCertificate 方法并非随处可用。 I found different solution by using Netsh.
我通过使用 Netsh 找到了不同的解决方案。
$iisCert = Get-ChildItem -Path "Cert:\LocalMachine\MY" `
| Where-Object { $_.FriendlyName -eq "IIS Express Development Certificate" } `
| Select-Object -First 1
$applicationId = [Guid]::NewGuid().ToString("B")
netsh http add sslcert ipport=0.0.0.0:443 certhash=$($iisCert.Thumbprint) appid=$applicationId
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.