Solved

Enumerate Certificate in the network

Posted on 2014-10-21
9
137 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 28

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 28

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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 28

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 28

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 28

Expert Comment

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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In today's information driven age, entrepreneurs have so many great tools and options at their disposal to help turn good ideas into a thriving business. With cloud-based online services, such as Amazon's Web Services (AWS) or Microsoft's Azure, bus…
This is a guide to the following problem (not exclusive but here) on Windows: Users need our support and we supporters often use global administrative accounts to do this. Using these accounts safely is a real challenge. Any admin who takes se…
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…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

760 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

16 Experts available now in Live!

Get 1:1 Help Now