Powershell - 在https绑定上设置SSL证书

Ken*_*ach 21 iis powershell ssl certificate

我正在尝试使用PowerShell在IIS站点上为自签名/本地证书设置SSL证书.

我创建了证书:

$newCert = 
       New-SelfSignedCertificate 
       -DnsName www.mywebsite.ru 
       -CertStoreLocation cert:\LocalMachine\My
Run Code Online (Sandbox Code Playgroud)

然后尝试设置SSL绑定:

get-item 
      cert:\LocalMachine\MY\$newCert.Thumbprint | 
      new-item -path IIS:\SslBindings\0.0.0.0!443
Run Code Online (Sandbox Code Playgroud)

如以下帖子所示:http://www.iis.net/learn/manage/powershell/powershell-snap-in-configuring-ssl-with-the-iis-powershell-snap-in

此处还显示: Powershell IIS7 Snap in将SSL证书分配给https绑定

我也尝试过:

get-item 
      cert:\LocalMachine\MY\$newCert.Thumbprint | 
      new-item -path IIS:\SslBindings\*!443
Run Code Online (Sandbox Code Playgroud)

无济于事,我没有在编辑站点绑定对话框中看到SSL证书集.

有什么想法吗?

Mar*_*ndl 32

您必须将证书分配给特定站点.

您可以使用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")
Run Code Online (Sandbox Code Playgroud)

  • 最后一行:指定的登录会话不存在。它可能已经被终止了。(HRESULT 异常:0x80070520) (3认同)
  • @ChuckD 这通常意味着您的私钥丢失或无法被 IIS 运行的用户访问。编辑:或者是的,它没有像理查德·斯奎尔斯所说的那样被导入。:D (2认同)