繁体   English   中英

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

[英]How can I get the most recent SSL certificate for a domain using PowerShell?

我正在尝试在 Web 托管证书存储中查找给定域(例如 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

似乎按 NotAfter 排序会导致在使用 Letsencrypt 时出现问题,而您仍然有 1 年的有效证书在 Letsencrypt 证书之后到期。

通过使用 NotBefore 进行排序使其工作......虽然没有测试太多。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM