Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Script to check all certs and expiration dates

Posted on 2015-02-20
3
Medium Priority
?
164 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 2000 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 19

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 19

Expert Comment

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

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
The Internet has made sending and receiving information online a breeze. But there is also the threat of unauthorized viewing, data tampering, and phoney messages. Surprisingly, a lot of business owners do not fully understand how to use security t…
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…

885 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