使用 Powershell 递归读取注册表设置

Read registry settings recursively with Powershell

我正在尝试使用 Powershell 递归读取一些注册表设置。 这是我试过的:

$registry = Get-ChildItem "HKLM:\Software\Wow6432Node\EODDashBoard\moveFilesOverflow" -Recurse
Foreach($a in $registry) {
    Write-Output $a.PSChildName
    $subkeys = (Get-ItemProperty  $a.pspath)
    Write-Output $subkeys.LastDateTime_EndScript

}

我希望能够在不知道注册表项的情况下列出所有注册表项及其值。

在我的脚本中,我有一个变量 $subkeys,其中包含我可以访问的对象。 (例如这里我可以访问$subkeys.LastDateTime_EndScript

然而,我想要的是在不知道我的脚本中的注册表项的情况下列出所有注册表项及其值,即像这样:

Foreach ($subkey in $subkeys) {
    Write-Output $subkey.keyname
    Write-Output $subkey.value
}

可能吗? 谢谢,

您可以遍历属性。使用你的想法是:

foreach ($a in $registry) {
    $a.Property | ForEach-Object {
        Write-Output $_
        Write-Output $a.GetValue($_)
    }
}

输出:

InstallDir
C:\Program Files\Common Files\Apple\Apple Application Support\
UserVisibleVersion
4.1.1
Version
4.1.1
....

虽然那很乱。在 powershell 中输出这样的数据的通常方法是创建一个具有名称和值属性的对象,因此每个注册表值都有一个对象。这更容易处理(如果您打算将它用于脚本中的某些内容)并且更容易在控制台中查看。

foreach ($a in $registry) {
    $a.Property | Select-Object @{name="Value";expression={$_}}, @{name="Data";expression={$a.GetValue($_)}}
}

foreach ($a in $registry) {
    ($a | Get-ItemProperty).Psobject.Properties |
    #Exclude powershell-properties in the object
    Where-Object { $_.Name -cnotlike 'PS*' } |
    Select-Object Name, Value
}

输出:

Value                 Data
-----                 ----
InstallDir            C:\Program Files\Common Files\Apple\Apple Application Support\
UserVisibleVersion    4.1.1
Version               4.1.1
....