Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xPackage: incorrect verbose message "Product installation cannot be determined" due to bug in conditional statement #446

Closed
harnsin opened this issue Oct 9, 2018 · 5 comments · Fixed by #447
Labels
stale The issue or pull request was marked as stale because there hasn't been activity from the community.

Comments

@harnsin
Copy link
Contributor

harnsin commented Oct 9, 2018

Details of the scenario you tried and the problem that is occurring

Hello all, I was working on a partial configuration using the xPackage Resource within xPSDesiredStateConfiguration and noticed incorrect output in the verbose statement due to an error in the conditional statement. It's a quick fix, the logic should be not equal to rather than equal to like the next set of logic below in the xPackage resource. This will result in proper ProductIsProduct validation and return the $productEntry rather than "Product installation cannot be determined".

Verbose logs showing the problem

# Verbose output from running the xPackage Resource

VERBOSE: [VmName]: LCM:  [ Start  Resource ]  [[xPackage]FileName]
VERBOSE: [VmName]: LCM:  [ Start  Test     ]  [[xPackage]FileName]
VERBOSE: [VmName]:                            [[xPackage]FileName] The path extension was .exe
VERBOSE: [VmName]:                            [[xPackage]FileName] Parsing XXX-XXXX-XXX-XXXX-XXXXX as an identifyingNumber
VERBOSE: [VmName]:                            [[xPackage]FileName] Parsed XXX-XXXX-XXX-XXXX-XXXXX as {XXX-XXXX-XXX-XXXX-XXXXX}
VERBOSE: [VmName]:                            [[xPackage]FileName] Ensure is Present
VERBOSE: [VmName]:                            [[xPackage]FileName] Product installation cannot be determined
VERBOSE: [VmName]:                            [[xPackage]FileName] product as boolean is True
VERBOSE: [VmName]:                            [[xPackage]FileName] The package FileName is installed
VERBOSE: [VmName]: LCM:  [ End    Test     ]  [[xPackage]FileName] True in 0.1090 seconds.
VERBOSE: [VmName]: LCM:  [ End    Resource ]  [[xPackage]FileName]

Suggested solution to the issue

Current code within conditional statement

# Lines 793-800 within xPackage Resource

    if ($null -eq $productEntry)
    {
        Write-Verbose -Message ($script:localizedData.ProductIsProduct -f $productEntry)
    }
    else
    {
        Write-Verbose -Message 'Product installation cannot be determined'
    }

Proposed code within conditional statement

# Change '-eq' to '-ne' on Line 793 within xPackage Resource

    if ($null -ne $productEntry)
    {
        Write-Verbose -Message ($script:localizedData.ProductIsProduct -f $productEntry)
    }
    else
    {
        Write-Verbose -Message 'Product installation cannot be determined'
    }

The DSC configuration that is used to reproduce the issue (as detailed as possible)

# Example Partial Configuration Script (removed specifics)

        xPackage FileName
        {
            Ensure     = 'Present'
            Name       = 'FileName'
            Path       = "C:\Temp\FileBinary.exe"
            ProductId  = 'XXX-XXXX-XXX-XXXX-XXXXX'
            Arguments  = '/q'
        }

# Lines 761-832 within xPackage Resource

    Assert-PathExtensionValid -Path $Path
    $uri = Convert-PathToUri -Path $Path
    $identifyingNumber = $null

    if (-not [String]::IsNullOrEmpty($ProductId))
    {
        $identifyingNumber = Convert-ProductIdToIdentifyingNumber -ProductId $ProductId
    }

    $getProductEntryParameters = @{
        Name = $Name
        IdentifyingNumber = $identifyingNumber
    }

    $checkRegistryValueParameters = @{
        CreateCheckRegValue = $CreateCheckRegValue
        InstalledCheckRegHive = $InstalledCheckRegHive
        InstalledCheckRegKey = $InstalledCheckRegKey
        InstalledCheckRegValueName = $InstalledCheckRegValueName
        InstalledCheckRegValueData = $InstalledCheckRegValueData
    }

    if ($CreateCheckRegValue)
    {
        Assert-RegistryParametersValid -InstalledCheckRegKey $InstalledCheckRegKey -InstalledCheckRegValueName $InstalledCheckRegValueName -InstalledCheckRegValueData $InstalledCheckRegValueData
        $getProductEntryParameters += $checkRegistryValueParameters
    }

    $productEntry = Get-ProductEntry @getProductEntryParameters

    Write-Verbose -Message ($script:localizedData.EnsureIsEnsure -f $Ensure)

    if ($null -eq $productEntry)
    {
        Write-Verbose -Message ($script:localizedData.ProductIsProduct -f $productEntry)
    }
    else
    {
        Write-Verbose -Message 'Product installation cannot be determined'
    }

    Write-Verbose -Message ($script:localizedData.ProductAsBooleanIs -f [Boolean]$productEntry)

    if ($null -ne $productEntry)
    {
        if ($CreateCheckRegValue)
        {
            Write-Verbose -Message ($script:localizedData.PackageAppearsInstalled -f $Name)
        }
        else
        {
            $displayName = Get-LocalizedRegistryKeyValue -RegistryKey $productEntry -ValueName 'DisplayName'
            Write-Verbose -Message ($script:localizedData.PackageAppearsInstalled -f $displayName)
        }
    }
    else
    {
        $displayName = $null

        if (-not [String]::IsNullOrEmpty($Name))
        {
            $displayName = $Name
        }
        else
        {
            $displayName = $ProductId
        }

        Write-Verbose -Message ($script:localizedData.PackageDoesNotAppearInstalled -f $displayName)
    }

    return ($null -ne $productEntry -and $Ensure -eq 'Present') -or ($null -eq $productEntry -and $Ensure -eq 'Absent')

The operating system the target node is running

OsName: Microsoft Windows Server 2016 Standard
OsOperatingSystemSKU: StandardServerEdition
OsArchitecture: 64-bit
WindowsBuildLabEx: 14393.0.amd64fre.rs1_release.160715-1616
OsLanguage: en-US
OsMuiLanguages: {en-US}

Version and build of PowerShell the target node is running

Name Value
---- -----
PSVersion 5.1.14393.0
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
BuildVersion 10.0.14393.0
CLRVersion 4.0.30319.42000
WSManStackVersion 3
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

xPSDesiredStateConfiguration 8.3.0.0

@harnsin
Copy link
Contributor Author

harnsin commented Oct 9, 2018

I have created a fork and made the quick change and pushing it up shortly.

@stale
Copy link

stale bot commented Nov 8, 2018

This issue has been automatically marked as stale because it has not had activity from the community in the last 30 days. It will be closed if no further activity occurs within 10 days. If the issue is labelled with any of the work labels (e.g bug, enhancement, documentation, or tests) then the issue will not auto-close.

@stale stale bot added the stale The issue or pull request was marked as stale because there hasn't been activity from the community. label Nov 8, 2018
@stale
Copy link

stale bot commented Dec 18, 2018

This issue has been automatically closed because it is has not had activity from the community in the last 40 days.

@harnsin
Copy link
Contributor Author

harnsin commented Dec 19, 2018

Reopening PR

@stale stale bot removed the stale The issue or pull request was marked as stale because there hasn't been activity from the community. label Dec 19, 2018
@stale
Copy link

stale bot commented Jan 18, 2019

This issue has been automatically marked as stale because it has not had activity from the community in the last 30 days. It will be closed if no further activity occurs within 10 days. If the issue is labelled with any of the work labels (e.g bug, enhancement, documentation, or tests) then the issue will not auto-close.

@stale stale bot added the stale The issue or pull request was marked as stale because there hasn't been activity from the community. label Jan 18, 2019
mhendric added a commit that referenced this issue Jan 28, 2019
xPackage: updated conditional statement to -ne to provide correct verbose output (fixes #446)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale The issue or pull request was marked as stale because there hasn't been activity from the community.
Projects
None yet
1 participant