Solved

Enumerate Certificate in the network

Posted on 2014-10-21
9
141 Views
Last Modified: 2014-10-23
Hi,

I would need to enumerates the certs which are installed on all the server in our network (windows 2003 & windows2008) ..

I would like to know are there any script available to collect the certificate information from w2k3 & windows 2008.

Thanks
0
Comment
Question by:stadmin
  • 5
  • 4
9 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 40396287
Here is a script that should work:


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 $_ | % {		
		$sub = $_.subject; $report += "$computer, $sub`n"
	}
	
}
$report | out-file C:\certreport.csv

Open in new window

0
 
LVL 1

Author Comment

by:stadmin
ID: 40396516
Hi,

we are getting below error while running the script

PS C:\Temp\Bios> server.domain.com
server.domain.com : The term 'server.domain.com' is not recognized as the name of a cmdlet
function, script file, or operable program. Check the spelling of the name, or if a path was included, verif
path is correct and try again.
At line:1 char:1
+ server.domain.com
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (server.domain.com:String) [], CommandNotFoundExcepti
    + FullyQualifiedErrorId : CommandNotFoundException
0
 
LVL 29

Expert Comment

by:becraig
ID: 40397352
Ok so it seems like you are missing something:

Steps:
1. Save the code snippet as <script>.ps1     (<script> being whatever name you want to give it)
Change the first line to map correctly to your server list, which should be a text file with one servername on each line.

$serverlist = "C:\foldername\serverlist.txt"
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 $serverlist | % {
	$computer = $_;
	Get-Cert $_ | % {		
		$sub = $_.subject; $report += "$computer, $sub`n"
	}
	
}
$report | out-file C:\certreport.csv

Open in new window

                                         

2. Open a powershell window and navigate to the path where you saved the ps1 file above
3. Ensure your server list which will be called with (gc c:\serverlist.txt) is in the right location ...
e.g.  C:\foldername\serverlist.txt
4. Run the script
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 1

Author Comment

by:stadmin
ID: 40398584
I did the same changed the path to match the server list .. saved the script as PS1 file.. and changed the output file location

still getting the same error
0
 
LVL 29

Expert Comment

by:becraig
ID: 40398589
Can you please post the error you are getting.

It isn't possible to help with seeing the error.

E.g your previous post shows:

PS C:\Temp\Bios> server.domain.com
server.domain.com : The term 'server.domain.com' is not recognized as the name of a cmdlet

But this is not a known command nor called out anywhere in the script I provided
0
 
LVL 1

Author Comment

by:stadmin
ID: 40398707
Thanks It worked; But I do need to know about the expiry dates of the certificates.. How dow e gather that info??

your help is very much appreciated
0
 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 40398714
Made an update to add the expiry to the values returned:
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 $_ | % {		
		$sub = $_.subject;$expiry = $_.notafter $report += "$computer, $sub, $expiry`n"
	}
	
}
$report | out-file C:\certreport.csv

Open in new window

0
 
LVL 1

Author Comment

by:stadmin
ID: 40398756
thanks alot for the help
0
 
LVL 29

Expert Comment

by:becraig
ID: 40398760
No problem, happy to help.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

No security measures warrant 100% as a "silver bullet". The truth is we also cannot assume anything but a defensive and vigilance posture. Adopt no trust by default and reveal in assumption. Only assume anonymity or invisibility in the reverse. Safe…
Our Group Policy work started with Small Business Server in 2000. Microsoft gave us an excellent OU and GPO model in subsequent SBS editions that utilized WMI filters, OU linking, and VBS scripts. These are some of experiences plus our spending a lo…
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). …

790 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