$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:LocalMachineMy}
会干净很多。