C# 如何使用powershell获取所有证书?

C# 如何使用powershell获取所有证书?,c#,.net,powershell,C#,.net,Powershell,我正在尝试使用powershell获取所有证书。当我将“\$computer\My”设置为下面的存储位置时,我想脚本会返回用户证书 当我设置“\$computer\root”时,它返回根证书。如何获得用户证书和计算机证书 $computer='localhost'; $ro=[System.Security.Cryptography.X509Certificates.OpenFlags]"ReadOnly" $lm=[System.Security.Cryptography.X509Certif

我正在尝试使用powershell获取所有证书。当我将“\$computer\My”设置为下面的存储位置时,我想脚本会返回用户证书

当我设置“\$computer\root”时,它返回根证书。如何获得用户证书和计算机证书

$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

有一个PSDrive
Cert
,它包含
CurrentUser
LocalMachine

这将为您提供所有证书:

Get-ChildItem Cert:\ -Recurse
可能重复的