Handle Open Key Excel Add-ins via PSADT

Hi All,

We have encountered an issue while using this code to create Open Keys. Main Article where we found the actual code is Here

It appears that the code is NOT generating a new OPEN key under HKCU:\SOFTWARE\Microsoft\Office\16.0\Excel\Options when there are NO or ZERO existing OPEN keys.

However, when there is at least one existing OPEN key, the code works as intended and generates incremental keys such as OPEN$inc (OPEN1, OPEN2, …).

## Function to Add an addon to Excel
## Example: Add-ExcelAddonOffice2016-SW -XlamFileSourcePath "$dirfiles\signal.xlam" -XlamFileTargetPath "$envProgramFilesx86\Microsoft Office\root\Office16\Library\Signal.xlam"
Function Add-ExcelAddonOffice2016 {
	[String]$XlamFileSourcePath = "",
	[String]$XlamFileTargetPath = ""
    $XlamName = Split-Path -Path $XlamFileSourcePath -Leaf
    Copy-File -Path $XlamFileSourcePath -Destination $XlamFileTargetPath #"$envProgramFilesx86\Microsoft Office\root\Office16\Library\Signal.xlam"

[Scriptblock]$InvokeXlam = {
    if ((Get-RegistryKey -Key "HKCU\SOFTWARE\Microsoft\Office\16.0\Excel\Options" -SID $UserProfile.SID) -and ($XlamName)) {
        $cnt = 0
        $OpenExist = $True
        $XlamOpenexist = $null
        While ($OpenExist) {
            if ($cnt -eq 0) {$OpenExist = Get-RegistryKey -Key "HKCU\SOFTWARE\Microsoft\Office\16.0\Excel\Options" -Value "OPEN" -SID $UserProfile.SID}
            else {$OpenExist = Get-RegistryKey -Key "HKCU\SOFTWARE\Microsoft\Office\16.0\Excel\Options" -Value "OPEN$cnt" -SID $UserProfile.SID}
            if ($OpenExist) {
                if ($openexist.ToLower() -Match $XlamName) {$XlamOpenexist = $True}
        if (!($XlamOpenexist) -and ($cnt -eq 0)) {Set-RegistryKey -Key "HKCU\SOFTWARE\Microsoft\Office\16.0\Excel\Options" -Name "OPEN" -Value "`"$XlamFileTargetPath`"" -Type String -SID $UserProfile.SID}
        if (!($XlamOpenexist) -and ($cnt -gt 0)) {Set-RegistryKey -Key "HKCU\SOFTWARE\Microsoft\Office\16.0\Excel\Options" -Name "OPEN$cnt" -Value "`"$XlamFileTargetPath`"" -Type String -SID $UserProfile.SID}
Invoke-HKCURegistrySettingsForAllUsers -RegistrySettings $InvokeXlam

Appreciate any ideas to solve this issue

OpenExist should be initialized with false.
$OpenExist = $False