diff --git a/sslcertificates/agents/windows/plugins/sslcertificates.ps1 b/sslcertificates/agents/windows/plugins/sslcertificates.ps1 index 6f28bd3e..900aa0a3 100755 --- a/sslcertificates/agents/windows/plugins/sslcertificates.ps1 +++ b/sslcertificates/agents/windows/plugins/sslcertificates.ps1 @@ -1,36 +1,23 @@ - Write-Host '<<>>' $UnixEpoch = (Get-Date -Date "01/01/1970") ; -foreach ($_ in Get-ChildItem -Recurse Cert:\LocalMachine\My) { - If ($_.DnsNameList) {$subject = $_.DnsNameList} - ElseIf ($_.Subject) {$subject = $_.Subject} - Else {$subject = $_.Thumbprint} +$CertLocations = "Cert:\LocalMachine\My", "Cert:\CurrentUser\My" - $data = [ordered]@{ - starts = (New-TimeSpan -Start $UnixEpoch -End $_.NotBefore).TotalSeconds ; - expires = (New-TimeSpan -Start $UnixEpoch -End $_.NotAfter).TotalSeconds ; - subj = $subject.Unicode ; - thumb = $_.Thumbprint ; - algosign = $_.SignatureAlgorithm.FriendlyName ; - } +foreach ($CertLocation in $CertLocations) { + foreach ($_ in Get-ChildItem -Recurse $CertLocation) { + If ($_.DnsNameList) {$subject = $_.DnsNameList} + ElseIf ($_.Subject) {$subject = $_.Subject} + Else {$subject = $_.Thumbprint} - $data | ConvertTo-Json -Compress -} + $data = [ordered]@{ + starts = (New-TimeSpan -Start $UnixEpoch -End $_.NotBefore).TotalSeconds ; + expires = (New-TimeSpan -Start $UnixEpoch -End $_.NotAfter).TotalSeconds ; + subj = $subject.Unicode ; + thumb = $_.Thumbprint ; + algosign = $_.SignatureAlgorithm.FriendlyName ; + } -foreach ($_ in Get-ChildItem -Recurse Cert:\CurrentUser\My) { - If ($_.DnsNameList) {$subject = $_.DnsNameList} - ElseIf ($_.Subject) {$subject = $_.Subject} - Else {$subject = $_.Thumbprint} - - $data = [ordered]@{ - starts = (New-TimeSpan -Start $UnixEpoch -End $_.NotBefore).TotalSeconds ; - expires = (New-TimeSpan -Start $UnixEpoch -End $_.NotAfter).TotalSeconds ; - subj = $subject.Unicode ; - thumb = $_.Thumbprint ; - algosign = $_.SignatureAlgorithm.FriendlyName ; + $data | ConvertTo-Json -Compress } - - $data | ConvertTo-Json -Compress }