powershell - 如何为网站绑定选择新安装的 SSL 证书
问题描述
我正在使用 cert util 命令添加 ssl 证书,但是在添加证书后,如何使用 power shell 为所有托管的网站选择新证书
我尝试在 powershell 下选择新安装的证书,但我收到错误 SSL 证书添加失败,错误:183 当该文件已存在时无法创建文件。有时,SSL 证书添加失败,错误:1312 指定的登录会话不存在。它可能已经被终止
$hostname="*.domain.net"
$cert = (Get-ChildItem cert:\LocalMachine\My | where-object { $_.Subject -like "*$hostname*" } | Select-Object -First 1).Thumbprint
$guid = [guid]::NewGuid().ToString("B")
netsh http add sslcert ipport="${IPAddressV2}:443" certhash=$cert certstorename=MY appid="$guid"
netsh http add sslcert ipport="${IPAddressV3}:443" certhash=$cert certstorename=MY appid="$guid"
netsh http add sslcert ipport="127.0.0.1:443" certhash=$cert certstorename=MY appid="$guid"
解决方案
这是自动为端口号为 443 的所有绑定选择新安装的证书的工作脚本
Import-Module Webadministration
IIS:
$IPAddress = "C:\Ipaddress.txt"
$Bindings = Get-WebBinding | Where-Object {$_.protocol -eq "https"} | Select-Object -ExpandProperty bindingInformation
$IPs = $Bindings | ForEach-Object { @($_ -split ':')[0]}
$IPs = @($IPs |Sort-Object -Unique) > $IPAddress
Import-Module Webadministration
$Friendlyname="*.abcd.com"
Get-ChildItem cert:\LocalMachine\My | where-object { $_.Subject -like "*$Friendlyname*" }
$hostname = Get-Content C:\Ipaddress.txt
foreach ($name in $hostname) {
$cert = (Get-ChildItem cert:\LocalMachine\My | where-object { $_.Subject -like "*$Friendlyname*" } | Select-Object -First 1).Thumbprint
Remove-Item -path "IIS:\SslBindings\${name}!443"
TIMEOUT /T 5 /NOBREAK
New-Item -path "IIS:\SslBindings\$name!443" -Thumbprint $cert}
推荐阅读
- linux - 设置 Linux 文件句柄分配限制
- reactjs - react测试库中按标签查询material-ui输入
- visual-studio-code - 使用原始 vim 中的 :edit 和 `tab` 时的不同 VSCodeVim 行为
- alfresco-share - Alfresco 文档下载网址不起作用
- javascript - webapi项目如何接受来自客户端的值并将其传递给.html?
- node.js - json2csv没有明智地下载正确的数据列
- java - 没有预设 Content-Type 'null' 的 [class org.springframework.mock.web.MockMultipartFile] 转换器]
- javascript - 无论上传多大尺寸的照片,如何让用户的图像不模糊?
- python - AWS Python 套接字客户端 TimeoutError:[WinError 10060] 连接尝试失败
- python - 如何在多线程烧瓶中使用 psycopg2