$Srv ='10.101.22.82' #remote server
$key = "SOFTWARE\\Microsoft\\SystemCertificates\\MY\\Certificates"
$type = [Microsoft.Win32.RegistryHive]::LocalMachine
$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($type, $Srv)
$regKey = $regKey.OpenSubKey($key)
Write-Host "Sub Keys"
Write-Host "--------"
Foreach($sub in $regKey.GetSubKeyNames())
{
#open the subkey here and parse the contents
$myStr = "SOFTWARE\\Microsoft\\SystemCertificates\\MY\\Certificates\\"+$sub
$regKey2 = $regKey.OpenSubKey($myStr)
$bytes = $regKey2.GetValue($sub).Blob
echo $bytes
$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]$bytes
$cert | Select Subject, Issuer, NotBefore, NotAfter, Thumbprint, SerialNumber
}
我正在尝试使用 PowerShell 读取远程注册表并获取 SSL 证书。我错过了什么?不胜感激,谢谢
最佳答案
您是否在您查询的远程主机上启用了远程处理?如果是这样,像
Invoke-Command -Computername COMPUTER -ScriptBlock {Get-ChildItem Cert:\LocalMachine\My}
会干净很多。
关于c# - PowerShell 通过远程注册表获取证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26528884/