2015-09-04 131 views
12

我想使用PowerShell在IIS站点上设置自签名/本地证书的SSL证书。Powershell - 在https绑定上设置SSL证书

我创建证书:

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

然后尝试设置SSL绑定:http://www.iis.net/learn/manage/powershell/powershell-snap-in-configuring-ssl-with-the-iis-powershell-snap-in

这里也显示: Powershell IIS7 Snap in Assign SSL certificate to https binding

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

对这个职位如图所示

我也试过了:

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

无济于事,我没有看到编辑网站绑定对话框中设置的SSL证书。

有什么想法?

+0

使用'IIS:\ 443'的SslBindings \ 0.0.0.0代替'IIS :\ SslBindings \ * 443'!将站点绑定到此端口时,它将使用注册的证书。 –

回答

17

您必须将证书分配给特定网站。

您可以使用AddSslCertificate功能使用Get-WebBinding cmdlet的检索网站的绑定信息,并设置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")