Querying bitness key in registry

Hello to all,

I am trying to run PowerShell code that will install a certain software according to the Microsoft office bitness type (32 or 64 bit).
I am querying the registry for this string:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\16.0\Outlook
“bitness”

The problem is that when the bitness key is missing (That means that no Microsoft office is installed), the file C:\install\missing.txt is not opened.
When the key exist with x86 or x64, the files x86.txt or x64.txt opened.

Any idea what is wrong in my code?

Thank you
Amir

function CheckOffice2016Bitness {
    $registryPath = "HKLM:\SOFTWARE\Microsoft\Office\16.0\Outlook"
    $bitnessKey = "Bitness"

    if (Test-Path $registryPath) {
        $bitnessValue = (Get-ItemProperty -Path $registryPath).$bitnessKey

        if ($bitnessValue -eq "x86") {
            Start-Process 'C:\WINDOWS\system32\notepad.exe' -FilePath "C:\install\x86.txt"
        } elseif ($bitnessValue -eq "x64") {
            Start-Process 'C:\WINDOWS\system32\notepad.exe' -FilePath "C:\install\x64.txt"
        } else {
        }
    } else {
        Start-Process 'C:\WINDOWS\system32\notepad.exe' -FilePath "C:\install\missing.txt"
    }
}

Your description of the problem, and your logic, would suggest that Test-Path $registryPath always returns true. However, you can’t get the Bitness key because it doesn’t exist, so you’re hitting the else {} statement which does nothing.

Have you validated whether the path is always present, even if the key isn’t?