Inventory SSL Root Cert Remotely Using PowerShell

%3CLINGO-SUB%20id%3D%22lingo-sub-797301%22%20slang%3D%22en-US%22%3EInventory%20SSL%20Root%20Cert%20Remotely%20Using%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-797301%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20not%20well%20versed%20with%20PowerShell%20but%20after%20researching%20it%20appears%20PowerShell%20might%20be%20the%20tool%20I%20need.%26nbsp%3B%20I%20have%20a%20need%20to%20inventory%20all%20computers%20on%20my%20AD%20to%20confirm%20whether%20or%20not%20they%20have%20the%20necessary%20SSL%20root%20certs%20that%20I%20have%20attempted%20to%20push%20out%20via%20GPO.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMost%20computers%20do%20have%20the%20certs%20but%20I%20need%20to%20identify%20the%20ones%20that%20do%20not.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAll%20examples%20I've%20run%20across%20seem%20to%20include%20%22Path%20Cert%20%3A%5Clocalmachine%22.%20How%20do%20I%20replace%20'localmachine'%20for%20'computer%20name'%20to%20gather%20SSL%20cert%20info%20from%20remote%20computers%20on%20my%20LAN%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOne%20example%20but%20it%20is%20not%20entirely%20clear%20how%20I%20would%20modify%20this%20script%20to%20connect%20remotely%20to%20each%20machine%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20696px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F126252i5592ADFD53985D35%2Fimage-dimensions%2F696x37%3Fv%3D1.0%22%20width%3D%22696%22%20height%3D%2237%22%20alt%3D%22clipboard_image_0.png%22%20title%3D%22clipboard_image_0.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdevblogs.microsoft.com%2Fscripting%2Fget-certificate-info-into-a-csv-by-using-powershell%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EGet%20certificate%20info%20into%20a%20CSV%20by%20using%20PowerShell%3C%2FA%3E%3C%2FP%3E%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fnotesofascripter.com%2F2016%2F09%2F19%2Fusing-powershell-work-ssl-certificates%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EUsing%20PowerShell%20to%20work%20with%20SSL%20Certificates%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-797301%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-797665%22%20slang%3D%22en-US%22%3ERe%3A%20Inventory%20SSL%20Root%20Cert%20Remotely%20Using%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-797665%22%20slang%3D%22en-US%22%3E%3CP%3E%22LocalMachine%22%20is%20the%20name%20of%20the%20cert%20container%2C%20it%20will%20have%20the%20same%20value%20on%20all%20computers.%20You%20can%20either%20use%20Invoke-Command%20to%20run%20the%20cmdlet%20against%20each%20computer%20(example%20%3CA%20href%3D%22https%3A%2F%2Fwww.powershellbros.com%2Fpowershell-tip-of-the-week-get-certificate-remotely%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.powershellbros.com%2Fpowershell-tip-of-the-week-get-certificate-remotely%2F%3C%2FA%3E)%20or%20use%20the%20built-in%20capabilities%20of%20the%20.NET%20method%20(example%20here%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fwww.experts-exchange.com%2Fquestions%2F28623585%2FNeed-to-get-certificates-inventory-for-each-server-into-the-spreadsheet-such-as-expiration-date-name-of-the-cert-issuer-cert-purpose.html%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.experts-exchange.com%2Fquestions%2F28623585%2FNeed-to-get-certificates-inventory-for-each-server-into-the-spreadsheet-such-as-expiration-date-name-of-the-cert-issuer-cert-purpose.html%3C%2FA%3E)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-815771%22%20slang%3D%22en-US%22%3ERe%3A%20Inventory%20SSL%20Root%20Cert%20Remotely%20Using%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-815771%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F58%22%20target%3D%22_blank%22%3E%40Vasil%20Michev%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20been%20trying%20to%20get%20up%20to%20speed%20by%20reviewing%20the%20links%20you%20sent.%20I%20can%20manually%20add%20the%20list%20of%20computers%20to%20scan%20as%20I%20learn%20how%20to%20read%20a%20CSV.%20But%20my%20question%20now%20is%20how%20do%20I%20turn%20%22LocalMachine%22%20into%20reading%20the%20%22Trusted%20Root%20Certificate%20Authorities%5CCertificates%22%20for%20both%20'Current%20User'%20%26amp%3B%20'Local%20Computer'%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-816521%22%20slang%3D%22en-US%22%3ERe%3A%20Inventory%20SSL%20Root%20Cert%20Remotely%20Using%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-816521%22%20slang%3D%22en-US%22%3E%3CP%3EIt's%20as%20simple%20as%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Edir%20Cert%3A%5CCurrentUser%5CRoot%5C%0Adir%20Cert%3A%5CLocalMachine%5CRoot%5C%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-818094%22%20slang%3D%22en-US%22%3ERe%3A%20Inventory%20SSL%20Root%20Cert%20Remotely%20Using%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-818094%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F58%22%20target%3D%22_blank%22%3E%40Vasil%20Michev%3C%2FA%3E%2C%20That%20seems%20simple%20enough%20in%20theory.%20But%20sadly%20once%20I%20ask%20for%20details%20on%20certs%20in%20that%20location%20I%20get%20nothing%20but%20the%20computer%20name%20when%20using%20the%20following%20example.%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20718px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F128045i9B27AC6477EC6054%2Fimage-dimensions%2F718x307%3Fv%3D1.0%22%20width%3D%22718%22%20height%3D%22307%22%20alt%3D%22clipboard_image_0.png%22%20title%3D%22clipboard_image_0.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20trying%20to%20find%202%20specific%20certs%20in%20this%20location.%20And%20if%20they%20don't%20exist%20in%20this%20location%20I%20need%20to%20know%20which%20computer%20it%20is%20that%20needs%20them%20installed.%20Or%20stated%20another%20way%20if%20I%20can%20get%20a%20report%20that%20tells%20me%20the%20cert%20%22IssuedTo%22%20descriptor%20and%20the%20%22Expiration%20Date%22.%20Ultimately%20I%20need%20to%20install%20the%20proper%20certs%20if%20they%20don't%20exist.%20I%20can%20do%20that%20manually.%20Heck%2C%20I%20can%20do%20all%20of%20this%20manually%20but%20it%20would%20be%20nice%20if%20I%20work%20smarter%20not%20harder.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20if%20I%20could%20do%20this%20I%20would%20like%20to%20parse%20a%20csv%20that%20contains%20the%20computer%20names%20that%20I%20need%20to%20check%20for%20certs%20in%20'CurrentUser%5CRoot'%20%26amp%3B%20'LocalMachine%5CRoot'%20that%20have%20an%20'Issue%20To'%20name%20of%20'SSL_Cert_1'%20%26amp%3B%20'SSL_Cert_2'%20and%20also%20display%20the%20'Expiration%20Date'%20associated%20with%20each%20cert.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEach%20computer%20that%20does%20not%20have%20the%20required%20certs%20I%20would%20like%20to%20install%20these%20certs.%20Or%20at%20the%20very%20least%20list%20them%20so%20I%20can%20pay%20a%20visit.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUnfortunately%20I%20can't%20even%20begin%20to%20write%20the%20proper%20syntax%20to%20include%20something%20like%20the%20following.%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20727px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F128046i33A6CB68B912C787%2Fimage-dimensions%2F727x311%3Fv%3D1.0%22%20width%3D%22727%22%20height%3D%22311%22%20alt%3D%22clipboard_image_1.png%22%20title%3D%22clipboard_image_1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-819460%22%20slang%3D%22en-US%22%3ERe%3A%20Inventory%20SSL%20Root%20Cert%20Remotely%20Using%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-819460%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20first%20example%20will%20only%20list%20certificates%20with%20CN%20matching%20the%20name%20of%20the%20computer%2C%20so%20it's%20seem%20to%20me%20its%20working%20as%20expected.%20You%20can%20simply%20remove%20the%20where%20clause%20and%20get%20a%20full%20list%20of%20certificates%2C%20the%20filter%20it%20out%20in%20excel%20or%20something.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-819901%22%20slang%3D%22en-US%22%3ERe%3A%20Inventory%20SSL%20Root%20Cert%20Remotely%20Using%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-819901%22%20slang%3D%22en-US%22%3E%3CP%3EWell%2C%20I%20did%20get%20the%20first%20one%20to%20work%20so%20to%20speak.%20It%20output%20listed%20the%20computers%20that%20it%20ran%20against.%20But%20it%20was%20unable%20to%20provide%20any%20of%20the%20cert%20data.%20Those%20fields%20were%20blank.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-820711%22%20slang%3D%22en-US%22%3ERe%3A%20Inventory%20SSL%20Root%20Cert%20Remotely%20Using%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-820711%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F58%22%20target%3D%22_blank%22%3E%40Vasil%20Michev%3C%2FA%3E%2C%26nbsp%3Bif%20you%20would%20kindly%20share%20with%20me%20the%20proper%20terminology%20I%20would%20be%20glad%20to%20research%20further%20on%20my%20own.%20I'm%20just%20not%20sure%20where%20to%20look%20for%20clarification%20on%20these%20commands.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-821479%22%20slang%3D%22en-US%22%3ERe%3A%20Inventory%20SSL%20Root%20Cert%20Remotely%20Using%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-821479%22%20slang%3D%22en-US%22%3E%3CP%3EAgain%2C%20the%20example%20above%20checks%20only%20for%20a%20specific%20certificate%2C%20one%20that%20has%20the%20CN%20set%20to%20the%20computer%20name.%20Just%20remove%2Fchange%20that%20part%20to%20get%20all%20the%20certificates%20instead.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Contributor

I am not well versed with PowerShell but after researching it appears PowerShell might be the tool I need.  I have a need to inventory all computers on my AD to confirm whether or not they have the necessary SSL root certs that I have attempted to push out via GPO. 

 

Most computers do have the certs but I need to identify the ones that do not.

 

All examples I've run across seem to include "Path Cert :\localmachine". How do I replace 'localmachine' for 'computer name' to gather SSL cert info from remote computers on my LAN?

 

One example but it is not entirely clear how I would modify this script to connect remotely to each machine:

clipboard_image_0.png

 

Get certificate info into a CSV by using PowerShell

Using PowerShell to work with SSL Certificates

 

 

8 Replies
Highlighted

"LocalMachine" is the name of the cert container, it will have the same value on all computers. You can either use Invoke-Command to run the cmdlet against each computer (example https://www.powershellbros.com/powershell-tip-of-the-week-get-certificate-remotely/) or use the built-in capabilities of the .NET method (example here: https://www.experts-exchange.com/questions/28623585/Need-to-get-certificates-inventory-for-each-serv...)

Highlighted

Thanks @Vasil Michev ,

 

I've been trying to get up to speed by reviewing the links you sent. I can manually add the list of computers to scan as I learn how to read a CSV. But my question now is how do I turn "LocalMachine" into reading the "Trusted Root Certificate Authorities\Certificates" for both 'Current User' & 'Local Computer'?

Highlighted

It's as simple as:

 

dir Cert:\CurrentUser\Root\
dir Cert:\LocalMachine\Root\
Highlighted

Hi @Vasil Michev, That seems simple enough in theory. But sadly once I ask for details on certs in that location I get nothing but the computer name when using the following example.:

 

clipboard_image_0.png

 

I'm trying to find 2 specific certs in this location. And if they don't exist in this location I need to know which computer it is that needs them installed. Or stated another way if I can get a report that tells me the cert "IssuedTo" descriptor and the "Expiration Date". Ultimately I need to install the proper certs if they don't exist. I can do that manually. Heck, I can do all of this manually but it would be nice if I work smarter not harder.

 

So if I could do this I would like to parse a csv that contains the computer names that I need to check for certs in 'CurrentUser\Root' & 'LocalMachine\Root' that have an 'Issue To' name of 'SSL_Cert_1' & 'SSL_Cert_2' and also display the 'Expiration Date' associated with each cert.

 

Each computer that does not have the required certs I would like to install these certs. Or at the very least list them so I can pay a visit.

 

Unfortunately I can't even begin to write the proper syntax to include something like the following.:

 

clipboard_image_1.png

 

Highlighted

The first example will only list certificates with CN matching the name of the computer, so it's seem to me its working as expected. You can simply remove the where clause and get a full list of certificates, the filter it out in excel or something.

Highlighted

Well, I did get the first one to work so to speak. It output listed the computers that it ran against. But it was unable to provide any of the cert data. Those fields were blank.

Highlighted

@Vasil Michev, if you would kindly share with me the proper terminology I would be glad to research further on my own. I'm just not sure where to look for clarification on these commands.

 

Thanks,

 

Highlighted

Again, the example above checks only for a specific certificate, one that has the CN set to the computer name. Just remove/change that part to get all the certificates instead.