Searching for display name and version and writing the output

I am trying to search for app display name 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) registry and provide output. 

$appver = 10.3.10.12406962
$appname = "VMware Tools"

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"}

Parents
No Data
Reply
  • I got the script which wanted, sharing it here. It may help someone. This script will connect to a remote computer and match the displayname and display version and write-output.

    param ([Parameter(Mandatory = $true)]
        [string]$ComputerName,
        [Parameter(Mandatory = $true)]
        [string]$appver,
        [Parameter(Mandatory = $true)]
        [string]$appname)
    
    Invoke-Command -ComputerName $ComputerName -ScriptBlock {
        $softwarex64 = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
        $softwarex32 = 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
        If ((Get-ChildItem -Path $softwarex64 -Recurse | Get-ItemProperty | Where-Object { $_.DisplayVersion -eq "$USING:appver" -and $_.DisplayName -eq "$USING:appname" }) ) { 
            Write-Host 'Installed 64' 
        }
        ElseIf ((Get-ChildItem -Path $softwarex32 -Recurse | Get-ItemProperty | Where-Object { $_.DisplayVersion -eq "$USING:appver" -and $_.DisplayName -eq "$USING:appname" }) ) { 
            Write-Host 'Installed 32' 
        }
        else { 
            Write-Host "not installed" 
        }
    }
Children
No Data