Skip to content

Instantly share code, notes, and snippets.

@bharkr
Last active January 27, 2022 20:19
Show Gist options
  • Save bharkr/2b72cd0ee6022d3483ce3bfe8d9abf05 to your computer and use it in GitHub Desktop.
Save bharkr/2b72cd0ee6022d3483ce3bfe8d9abf05 to your computer and use it in GitHub Desktop.
Check for Incommon Certs
$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