Powershell 如何获取即将过期的受信任toot证书(60天)
我正在尝试获取将在60天后过期的受信任根证书。这就是我目前所拥有的Powershell 如何获取即将过期的受信任toot证书(60天),powershell,shell,certificate,windows-server-2012-r2,script,Powershell,Shell,Certificate,Windows Server 2012 R2,Script,我正在尝试获取将在60天后过期的受信任根证书。这就是我目前所拥有的 $getcert=Get-ChildItem -Path Cert:\LocalMachine\AuthRoot -ExpiringInDays 60 foreach ($cert in $getcert) { $cert.issuer #how to get this? if($cert -ne "" -and $cert.issuer -notcontains "Root CA"
$getcert=Get-ChildItem -Path Cert:\LocalMachine\AuthRoot -ExpiringInDays 60
foreach ($cert in $getcert) {
$cert.issuer #how to get this?
if($cert -ne "" -and $cert.issuer -notcontains "Root CA" ){
"send notification"
$cert.FriendlyName
}else{
"continue"
}}
但我无法获取颁发者,我需要它以排除根CA或服务器创建的颁发者,这样我就可以知道Digicert之类的证书何时过期,然后发送通知(已经配置了mailgun,无需添加此部分)
MMC中有一个“颁发者”属性,但不知道如何通过PS找到它,有人能帮我吗?非常感谢您的帮助
谢谢,致以最诚挚的问候。继续我的评论,您可以筛选管道连接到
Where对象的非“根CA”证书,除非这不是全部筛选目的。因此,您可以这样做:
$Expriring_Certs = Get-ChildItem -Path Cert:\LocalMachine\AuthRoot -ExpiringInDays 60 | Where-Object {$_.Subject -notmatch "Root CA"}
foreach($Cert in $Expriring_Certs){
[PSCustomObject]@{
"Friendly Name" = $Cert.FriendlyName
" Cert Issuer " = $Cert.Issuer
"Expiration Date" = $Cert.NotAfter
}
}
将证书保存在变量中后,您可以执行$getcert[0]|选择*
并查看自己的属性名称和值。你应该在那里找到你要找的。你也可以在你的Get ChildItem
中对非“Root CA”进行筛选。谢谢,这正是我需要的!