当前位置: 移动技术网 > 科技>操作系统>windows > powershell 更新 IIS SSL 证书

powershell 更新 IIS SSL 证书

2020年04月16日  | 移动技术网科技  | 我要评论

湖北三类大学,雅安芦山县委书记,天使的翅膀伴奏

powershell 更新 iis ssl 证书

intro

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

solution

更新过程:

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

完整的更新脚本如下:

$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"

reference

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网