我正在尝试在给定域的Web Hosting证书存储中找到最新证书(例如www.example.com)
找到任意数量的匹配证书很容易,但我怎样才能找到最新的证书,按到期日期排序(最远的未来)?
我现有的代码是:
(Get-ChildItem -Path cert:\LocalMachine\WebHosting
| Where-Object {$_.Subject -match "example.com"}).Thumbprint;
但是,这有时会返回两个证书,因为通常先前的证书(续订之前)必须在证书存储中保留一段时间。
您可以尝试按属性notafter
排序
要查看所有属性:
(Get-ChildItem -Path cert:\LocalMachine\WebHosting | Where-Object {$_.Subject -match "example.com"}) | fl *
按notAfter
属性排序:
(Get-ChildItem -Path cert:\LocalMachine\ca | Where-Object {$_.Subject -match ".*microsoft.*"}) | Sort-Object -Property NotAfter -Descending