I am trying to search for app displayname and version and if matches write the output but not sure why it is not working as expected. Can someone pls guide me. DisplayName and version will be passed to the script as param. It will search registry in two (32/64) hives and provide output.
$appver = "1.2.3.4"
$appname = "App Name"
If ((Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall -Recurse | Get-ItemProperty | where {$_ -eq $appver}) -and
(Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall -Recurse | Get-ItemProperty | where {$_ -eq $appname}))
{Write-Host "Installed"}
ElseIf ((Get-ChildItem -Path HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall -Recurse | Get-ItemProperty | where {$_ -eq $appver}) -and
(Get-ChildItem -Path HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall -Recurse | Get-ItemProperty | where {$_ -eq $appname}))
{Write-Host "Installed"}
Else
{Write-Host "Not Installed"}
Thank you!