2015-09-04 136 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")