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

问题描述 投票:1回答:1

我正在尝试在给定域的Web Hosting证书存储中找到最新证书(例如www.example.com)

找到任意数量的匹配证书很容易,但我怎样才能找到最新的证书,按到期日期排序(最远的未来)?

我现有的代码是:

(Get-ChildItem -Path cert:\LocalMachine\WebHosting 
   | Where-Object {$_.Subject -match "example.com"}).Thumbprint;

但是,这有时会返回两个证书,因为通常先前的证书(续订之前)必须在证书存储中保留一段时间。

powershell ssl-certificate powershell-v3.0 octopus-deploy
1个回答
3
投票

您可以尝试按属性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
© www.soinside.com 2019 - 2024. All rights reserved.