How to Get All Certificates with Powershell?

I am trying to get all certificates with powershell. When I set "\$computer\My" as store location below script returns user certificates I think.

When I set "\$computer\root" it returns root certificates. How can I get both user and machine certificates?

$computer='localhost';
$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)
$certificates=$store.Certificates
1

2 Answers

There is a PSDrive Cert, which contains CurrentUser and LocalMachine.

So this get you all certificates:

Get-ChildItem Cert:\ -Recurse
0

Specifically to get user and localmachine certificates (only):

Get-ChildItem Cert:\LocalMachine\My | ft

Get-ChildItem Cert:\CurrentUser\My | ft

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest