简体   繁体   English

如何使用PowerShell将创建的证书添加到IIS https绑定

[英]How to add created certificate to an IIS https binding using PowerShell

I can create a self signed certificate with PowerShell: 我可以使用PowerShell创建自签名证书:

$cert = New-SelfSignedCertificate –DnsName www.test.com -CertStoreLocation “cert:\LocalMachine\My”

I also can create bindings for my site: 我还可以为我的网站创建绑定:

New-WebBinding -Name "Test" -IPAddress "*" -Protocol "https" -Port 443 -HostHeader www.test.com -SslFlags 1

However based on the documentation New-WebBinding has no parameter which accepts a certificate see: New-WebBinding documentation 但是,根据文档New-WebBinding没有可以接受证书的参数, 请参阅:New-WebBinding文档

Question

How can I properly create the https binding which is using the created certificate? 如何正确使用创建的证书创建https绑定?

From this related question . 这个相关的问题 Replace 127.0.0.1 with your IP address: 将127.0.0.1替换为您的IP地址:

Import-Module Webadministration
$IPAddress = '127.0.0.1' #your IIS server IP address
New-WebBinding -Name "Default Web Site" -Protocol "https" -IPAddress $IPAddress -Port 443 -HostHeader "www.test.com"
$SSLCert = Get-ChildItem –Path "cert:\LocalMachine\My" | 
  Where-Object {$_.subject -like 'cn=www.test.com*'}
New-Item "IIS:SslBindings\$IPAddress!443" -value $SSLCert 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM