Solved

Script to check all certs and expiration dates

Posted on 2015-02-20
3
133 Views
Last Modified: 2015-02-20
I need to find all certs on all servers remotely and found this code by Becraig, which works, but it doesn't include expiration date.  Would like the expiration date included in the output.  I appreciate the help!

function Get-Cert( $computer){
    $ro=[System.Security.Cryptography.X509Certificates.OpenFlags]"ReadOnly"
    $lm=[System.Security.Cryptography.X509Certificates.StoreLocation]"LocalMachine"
    $store=new-object System.Security.Cryptography.X509Certificates.X509Store("\\$computer\My",$lm)
    $store.Open($ro)
    $store.Certificates

}
gc c:\serverlist.txt | % {
$computer=$_;
Get-Cert $_ | ?{
$_.subject -like "*domain.domain.com*";

} | % {

$sub = $_.subject;$report += "$computer, $sub`n" }

}
$report | out-file C:\certreport.csv

Open in new window

0
Comment
Question by:mystikal1000
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
OriNetworks earned 500 total points
ID: 40622222
You should be able to change

$sub = $_.subject;$report += "$computer, $sub`n" }

To
$sub = $_.subject;$expires=$_.NotAfter;$report += "$computer, $sub, $expires`n" }
0
 
LVL 18

Expert Comment

by:Raheman M. Abdul
ID: 40622244
Try this  (not tested).
function Get-Cert( $computer){
    $ro=[System.Security.Cryptography.X509Certificates.OpenFlags]"ReadOnly"
    $lm=[System.Security.Cryptography.X509Certificates.StoreLocation]"LocalMachine"
    $store=new-object System.Security.Cryptography.X509Certificates.X509Store("\\$computer\My",$lm)
    $store.Open($ro)
    $store.Certificates

}
gc c:\serverlist.txt | % {
$computer=$_;
Get-Cert $_ | ?{
$_.subject -like "*domain.domain.com*";

} | % {

$exp = $_.Notafter; $sub = $_.subject;$report += "$computer, $sub, $exp`n" }

}
$report | out-file C:\certreport.csv

Open in new window

0
 
LVL 18

Expert Comment

by:Raheman M. Abdul
ID: 40622246
Sorry OriNetworks, I did not see your comment before posting.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question