检查远程计算机中是否存在注册表路径



我使用此命令使用 Power Shell 检查是否存在路径。Powershell测试路径"HKCU:\Software\Microsoft\Windows"现在如何将其扩展到远程机器。如果我想在远程机器中测试注册表路径,语法是什么,我尝试了powershell测试路径"\\机器名称\HKCU:\软件\Microsoft\Windows",但它不起作用。建议一些方法来测试它。

您可以

按此处概述访问它:http://powershell.com/cs/blogs/tips/archive/2011/02/15/accessing-registry-remote.aspx

$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', 'server123')
$key = $reg.OpenSubKey('SOFTWAREMicrosoftWindowsCurrentVersionUninstall')
$key.GetSubKeyNames() | ForEach-Object {
    $subkey = $key.OpenSubKey($_)
    $i = @{}
    $i.Name = $subkey.GetValue('DisplayName')
    $i.Version = $subkey.GetValue('DisplayVersion')
    New-Object PSObject -Property $i
    $subkey.Close()
}
$key.Close()
$reg.Close()

另一种方法是启用 PSRemoting 并在远程计算机上使用 invoke-command,并有效地运行与在本地机器上运行的命令相同的命令。

无法连接到远程计算机的当前用户配置单元。下面是使用远程注册表模块检查远程服务器的 hklm 配置单元中是否存在远程密钥的示例。该模块可以在 codeplex 上找到:psremoteregistry.codeplex.con

Test-RegKey -ComputerName server1 -Key software\microsoft\winows -Hive LocalNachine

这个网站帮助了我。 代码基本上检查一个密钥,然后检查另一个密钥,如果第一个密钥不存在。 它还会在尝试从中读取值之前验证子项是否存在。 如果两者都不存在,尝试/捕获可以帮助解决这个问题。

   $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computerName)
    $regkey = $reg.OpenSubkey("SOFTWARE\Symantec\Symantec Endpoint Protection\AV\Storages\Filesystem\RealTimeScan")
if(-not $regkey) {
$regkey = $reg.OpenSubkey("SOFTWARE\Wow6432Node\Symantec\Symantec Endpoint Protection\AV\Storages\Filesystem\RealTimeScan")
}
$autoProtectStatus = ""
$null = ""
if ($regkey.GetValue("OnOff", $null) -ne $null) {
    $autoProtectStatus = $regkey.GetValue("OnOff")
}
if ($autoProtectStatus -eq 1) {
    $autoProtectStatus = "Protection On"
} elseif ($autoProtectStatus -eq 0) {
    $autoProtectStatus = "Protection Off"
} else {
    $autoProtectStatus = "Unknown State"
}

很多问答都是3岁或以上的。我怀疑较新版本的Powershell一定已经清理了很多。话虽如此,仍然没有直接命令来检查远程计算机上的注册表(据我所知)。这有效 - 它检查是否安装了 .NET 4.6.2(它比其他答案更简单吗?

invoke-command -computername <NetBiosName> -scriptblock {test-path -Path
"HKLM:SoftwareMicrosoft.NetFrameworkv4.0.30319SKUs.NetFramework,   
Version=v4.6.2"}

您还可以将脚本块内容放入 *.ps1 文件({} 中的所有内容),然后使用以下方法调用它:Invoke-Command -ComputerName NetBiosName -FilePath "FQLP"

最新更新