Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell - X509Certificates.X509Store get all certificates?

I want to get all certificates from my system. So I used the System.Security.Cryptography.X509Certificates class. When I remove the () after the X509Store I getting the same results like I entered "My"

What is the right membername to see all certificates? It is possible?

MSDN StoreName Enumeration

$store=new-object System.Security.Cryptography.X509Certificates.X509Store("CA")
# Put in CA, My, root etc.
$store.open("ReadOnly")
$store.Certificates
$store.Certificates.count 
like image 292
LaPhi Avatar asked Feb 23 '23 22:02

LaPhi


2 Answers

You can get them from your local cert drive:

Get-ChildItem Cert:\CurrentUser\CA # user certs

Get-ChildItem Cert:\LocalMachine\CA # machine certs
like image 183
Shay Levy Avatar answered Mar 06 '23 21:03

Shay Levy


Get-ChildItem Cert:\LocalMachine\My

This is fun if you have WinRM installed but in a much more standard way to find all certificate it is much better to use something like

$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("\\$server_name\My","LocalMachine")

$store.Open("ReadOnly")             
$store.Certificates
like image 42
Nerigal Avatar answered Mar 06 '23 22:03

Nerigal