读取Host的证书并输出到Splunk
我的大脑出现了障碍,不知道如何解决。
我有以下脚本:
$CorrelationId = New-Guid
$Server = Get-WMIObject Win32_ComputerSystem| Select-Object -ExpandProperty Name
$getcert= Get-ChildItem cert:\LocalMachine\My -Recurse | Where-Object {$_ -is [System.Security.Cryptography.X509Certificates.X509Certificate2] -and ($_.NotAfter -lt (Get-Date).AddDays(45)) -and($_.Issuer -eq "CN=test.at, DC=ds, DC=test, DC=at")} | Select-Object -Property Issuer, NotAfter, Subject, FriendlyName
$notafter = $getcert.NotAfter
$Subject = $getcert.Subject
$issuer = $getcert.Issuer
$FriendlyName= $getcert.FriendlyName
Write-Log -D Console,Splunk -L Info -A Servercertificate -M " Certificate $Subject on Host $Server with issuer $issuer and FriendlyName $FriendlyName expires at $notafter" -CorrelationId $CorrelationId -EventId 1
只要我只有 1 个证书,它就可以正常工作,但如果我有多个证书,它就只能连线了。
我知道可以用 foreach 解决这个问题,但我不知道该怎么做。
感谢您的帮助
i got block in my brain and don`t know how to fix ist.
i have following script:
$CorrelationId = New-Guid
$Server = Get-WMIObject Win32_ComputerSystem| Select-Object -ExpandProperty Name
$getcert= Get-ChildItem cert:\LocalMachine\My -Recurse | Where-Object {$_ -is [System.Security.Cryptography.X509Certificates.X509Certificate2] -and ($_.NotAfter -lt (Get-Date).AddDays(45)) -and($_.Issuer -eq "CN=test.at, DC=ds, DC=test, DC=at")} | Select-Object -Property Issuer, NotAfter, Subject, FriendlyName
$notafter = $getcert.NotAfter
$Subject = $getcert.Subject
$issuer = $getcert.Issuer
$FriendlyName= $getcert.FriendlyName
Write-Log -D Console,Splunk -L Info -A Servercertificate -M " Certificate $Subject on Host $Server with issuer $issuer and FriendlyName $FriendlyName expires at $notafter" -CorrelationId $CorrelationId -EventId 1
as long i have just 1 Cert it works proper, but if i got more than one it`s just wired.
I know that it is may possible to fix this with foreach, but i don`t know how to do it.
Thanks for your Help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的
Write-Log
命令按预期工作,并且您希望每个证书都有一个唯一的 CorrelationId,那么它应该相当简单。例如:
If your
Write-Log
command is working as expected, and you'd prefer to have a unique CorrelationId per certificate, then it should be fairly straightforward.For example: