简体   繁体   中英

How to add created certificate to an IIS https binding using PowerShell

I can create a self signed certificate with 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

Question

How can I properly create the https binding which is using the created certificate?

From this related question . Replace 127.0.0.1 with your IP address:

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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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