最近发现咱们开发环境的 IIS 上的 SSL 证书过时了,为了后面方便维护和更新,搞了一个 powershell 脚本,之后要更新的时候直接跑一下脚本就能够了,因此有了这篇文章web
更新过程:shell
完整的更新脚本以下:windows
$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"