[英]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中输出这种数据的通常方法是创建一个具有Name和Value属性的对象,因此每个注册表值有一个对象。 这更容易处理(如果您打算将其用于脚本中的某些内容),并且更容易在控制台中查看。
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
....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.