2

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

4

4 回答 4

3

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

$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', 'server123')
$key = $reg.OpenSubKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall')

$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在远程机器上使用,并有效地运行与在本地机器上运行的命令相同的命令。

于 2012-04-23T06:13:46.030 回答
0

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

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

于 2012-04-23T08:51:07.900 回答
0

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

   $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"
}
于 2013-08-21T21:31:47.743 回答
0

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

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

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

于 2017-05-10T18:41:16.550 回答