Last active
January 27, 2022 20:19
-
-
Save bharkr/2b72cd0ee6022d3483ce3bfe8d9abf05 to your computer and use it in GitHub Desktop.
Check for Incommon Certs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$servers = @('server2','server1') | |
$report_csv = "C:\users\$env:username\desktop\cert_report.csv" | |
$Results = @() | |
$Results = Invoke-Command -ComputerName $Servers { | |
$Certs = @{} | Select Certificate,Expired | |
$Cert = Get-ChildItem Cert:\LocalMachine\My | Where-Object {$_.issuer -match 'Incommon'} | |
If($Cert){ | |
$Certs.Certificate = $Cert.subject | |
$Certs.Expired = $Cert.NotAfter | |
} | |
Else{ | |
$Certs.Certificate = " - " | |
$Certs.Expired = " - " | |
} | |
$Certs | |
} | Select-Object @{n='ServerName';e={$_.pscomputername}},Certificate,Expired | |
#Display results in console | |
$Results | Sort-Object Expired -Descending | |
#Save results to CSV file | |
$Results | Sort-Object Expired -Descending | Export-Csv -Path $report_csv -NoTypeInformation -Force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment