If you need to get all certificates, from a list of remote computers, you can use this script:
$Servers = "kennethdalbjerg-dc01",
"kennethdalbjerg-dc02",
"kennethdalbjerg-exch01",
"kennethdalbjerg-fs01"
$Results = @()
$Results = Invoke-Command -cn $Servers {
$Certs = @{} | Select Certificate,Expired
$Cert = Get-ChildItem Cert:\LocalMachine\My
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 C:\users\$env:username\desktop\cert_results.csv -NoTypeInformation -Force
#Open results in new window
$Results | Sort-Object Expired -Descending | Out-GridView -Title "Final results"