如何使用PowerShell获得域的最新SSL证书?

尼克

我正在尝试在虚拟主机证书存储中找到给定域的最新证书(例如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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章