且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Powershell脚本在IIS中查找当前绑定的过期证书

更新时间:2023-11-02 23:45:04

可以从IIS:提供程序获取绑定到网站的证书列表:

A list of the certificates bound to websites can be obtained from the IIS: provider:

Get-ChildItem IIS:SSLBindings

尝试一下:

$DaysToExpiration = 7

$expirationDate = (Get-Date).AddDays($DaysToExpiration)

$sites = Get-Website | ? { $_.State -eq "Started" } | % { $_.Name }
$certs = Get-ChildItem IIS:SSLBindings | ? {
           $sites -contains $_.Sites.Value
         } | % { $_.Thumbprint }

Get-ChildItem CERT:LocalMachine/My | ? {
  $certs -contains $_.Thumbprint -and $_.NotAfter -lt $expirationDate
}