Solved

Script to check all certs and expiration dates

Posted on 2015-02-20
3
119 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now