如何用PowerShell筛选出仅用于Server Authentication的最新证书
筛选仅含Server Authentication的最新证书
你的原命令会匹配所有包含Server Authentication用途的证书,包括同时带有Remote Desktop Authentication等其他用途的。要筛选仅用于Server Authentication的证书,需要同时检查增强密钥用途列表的条目数量和具体内容:
修正后的命令
Get-ChildItem -Recurse Cert:\LocalMachine\My | Where-Object { # 确保增强密钥用途只有1项,且该项是Server Authentication $_.EnhancedKeyUsageList.Count -eq 1 -and $_.EnhancedKeyUsageList.FriendlyName -eq 'Server Authentication' } | Sort-Object NotBefore -Descending | # 按证书创建时间倒序,取最新创建的 Select-Object -First 1
补充说明
- 如果你需要的是最晚到期的证书,把排序字段换成
NotAfter即可:Sort-Object NotAfter -Descending - 可以在最后加上具体字段查看验证,比如:
Select-Object Thumbprint, Subject, NotBefore, NotAfter, EnhancedKeyUsageList
内容的提问来源于stack exchange,提问作者udhayan dharmalingam
相关产品推荐
相关产品推荐

