简体   繁体   中英

Powershell - Searching value for 32 and 64 bits in registry

I currently working on powershell script who collect some datas into registry.

To perform these action, I use a similar code:

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

Question: in the example above, is it possible to find the value "ProductHotfix" in the 32 and 64 bit registry path?

Thanks by advance for your advices :)

Regards,

LEFBE

I would do something like below:

foreach ($path in 'HKLM:\SOFTWARE\XXXX\YYY\ZZZ\environment', 'HKLM:\SOFTWARE\WOW6432Node\XXXX\YYY\ZZZ\environment') {
    $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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM