系统城装机大师 - 固镇县祥瑞电脑科技销售部宣传站!

当前位置:首页 > server > anz > 详细页面

powershell 更新 IIS SSL 证书

时间:2020-04-24来源:电脑系统城作者:电脑系统城

powershell 更新 IIS SSL 证书

Intro#

最近发现我们开发环境的 IIS 上的 SSL 证书过期了,为了后面方便维护和更新,搞了一个 powershell 脚本,以后要更新的时候直接跑一下脚本就可以了,所以有了这篇文章

Solution#

更新过程:

  1. 移除之前老的证书
  2. 导入新的证书
  3. 移除旧的 ssl 证书
  4. 创建新的 ssl 证书绑定新的证书

完整的更新脚本如下:


 
Copy
$hostName = "xxx.com" $pfxCertPath = "C:\backup\xxxxx.pfx" $pfxCertPwdPath = "C:\backup\pfx-password.txt" $certImportPwd = Get-Content $pfxCertPwdPath | ConvertTo-SecureString -AsPlainText -Force # try remove before ssl certs Get-ChildItem "cert:\LocalMachine\My" | where-object { $_.Subject -like "*$hostName*" } | Remove-Item # import new ssl $importedCert = Import-PfxCertificate -FilePath $pfxCertPath -CertStoreLocation "Cert:\LocalMachine\My" -p $certImportPwd $certHash = $importedCert.Thumbprint # remove sslcert binding netsh http delete sslcert hostnameport="${hostName}:443" # add new sslcert binding $guid = [guid]::NewGuid().ToString("B") netsh http add sslcert hostnameport="${hostName}:443" certhash=$certHash certstorename=MY appid="$guid"

 

分享到:

相关信息

系统教程栏目

栏目热门教程

人气教程排行

站长推荐

热门系统下载