I have written the following script to check against an application name and echo back some properties if it's installed:
$input = "Microsoft Office Professional"
$appName = "*" + $input + "*"
$responseX64 = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {$_.DisplayName -like $appName} | Select-Object @{Expression={$_.DisplayName + "|" + $_.DisplayVersion +"|x64"}} | Sort-Object -Unique | ft -HideTableHeaders
$responseX86 = Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {$_.DisplayName -like $appName} | Select-Object @{Expression={$_.DisplayName + "|" + $_.DisplayVersion +"|x86"}} | Sort-Object -Unique | ft -HideTableHeaders
If (([string]::IsNullOrEmpty($responseX64)) -and ([string]::IsNullOrEmpty($responseX86)))
{
Write-Output "No matches found."
exit
}
else
{
Write-Output $responseX64
Write-Output $responseX86
}
For completeness I am checking both the x86 and x64 Uninstall registry keys. This works as expected when I run it in an x64 PowerShell session and correctly returns that I have a single x86 install of Microsoft Office:
Microsoft Office Professional Plus 2016|16.0.4266.1001|x86
However, when I run it on the same machine in an x86 session of PowerShell (as it will be run by my x86 management agent), I get the following return:
Microsoft Office Professional Plus 2016|16.0.4266.1001|x64
Microsoft Office Professional Plus 2016|16.0.4266.1001|x86
I have double-checked my registry entries under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall just to be sure there isn't some x64 artifact of Office in there, but there is nothing. How can I amend this script so that it returns accurate results when run in an x86 context?