绑定后将SSL证书分配给网站 - Powershell

时间:2017-01-24 01:35:10

标签: powershell http https binding ssl-certificate

美好的一天。如何在绑定http和https后自动为网站分配SSL证书?

我有这个代码,它绑定了http和https,但它没有分配SSL证书。也许你可以帮助我。提前谢谢。

 $thumbprint="########################################"
 $binding = @{protocol="http";bindingInformation=$ip+":80:"+$iisAppNameBinding}
 new-item $iisAppName -type site –physicalPath $directoryPath -bindings $binding

 $newBinding = (
      @{protocol="http";bindingInformation=$ip+":80:"+$iisAppNameBinding},
      @{protocol="https";bindingInformation=$ip+":443:"+$iisAppNameBinding;certificateStoreName="MY";certificateName=$thumbprint})
 Set-itemproperty $iisAppName -name bindings -value $newBinding

1 个答案:

答案 0 :(得分:0)

假设您的证书位于证书:LocalMachine \ My

import-module webadministration
$computerName = $Env:Computername
$domainName = $Env:UserDnsDomain
New-WebBinding -Name "MyWebSite" -IP "*" -Port 443 -Protocol https
Get-ChildItem cert:\LocalMachine\My | where { $_.Subject -match "CN\=$Computername\.$DomainName" } | select -First 1 | New-Item IIS:\SslBindings\0.0.0.0!443

另一种方法的参考链接:powershell-snap-in-configuring-ssl