Powershell-在注册表中搜索32位和64位的值



我目前正在编写powershell脚本,他将一些数据收集到注册表中。

为了执行这些操作,我使用了一个类似的代码:

$Ifkeyexist = Test-Path 'HKLM:SOFTWAREWOW6432NodeXXXXYYYZZZenvironment'
if ($Ifkeyexist -eq "True")
{
$GetProductHotfix = Get-ItemPropertyValue 'HKLM:SOFTWAREWOW6432NodeXXXXYYYZZZenvironment' 'ProductHotfix'
Write-host "- Product Hotfix: $GetProductHotfix"
}
else {
write-host "- Unable to find product hotfix" -ForegroundColor red
}
} 

问题:在上面的例子中;ProductHotfix";在32和64位注册表路径中?

提前感谢您的建议:(

问候,

lebbe

我会做如下操作:

foreach ($path in 'HKLM:SOFTWAREXXXXYYYZZZenvironment', 'HKLM:SOFTWAREWOW6432NodeXXXXYYYZZZenvironment') {
$hotfix = Get-ItemPropertyValue -Path $path  -Name 'ProductHotfix' -ErrorAction SilentlyContinue
# assuming you want to exit the loop at the first successfull 'hit'
if ($hotfix) { break }
}
if ($hotfix) {
Write-Host "- Product Hotfix: $hotfix"
}
else {
Write-Host "- Unable to find product hotfix" -ForegroundColor Red
}

最新更新