Skip to content

Fix Get-IntuneWin32AppSupersedence.ps1 logic for single-item responses#224

Open
Marco-Valle wants to merge 1 commit intoMSEndpointMgr:masterfrom
Marco-Valle:fix/supersedence-count
Open

Fix Get-IntuneWin32AppSupersedence.ps1 logic for single-item responses#224
Marco-Valle wants to merge 1 commit intoMSEndpointMgr:masterfrom
Marco-Valle:fix/supersedence-count

Conversation

@Marco-Valle
Copy link
Copy Markdown

Description

This PR resolves an issue where Get-IntuneWin32AppSupersedence fails to return data in Windows PowerShell 5.1 when exactly one relationship exists.

In Windows PowerShell, [PSCustomObject] scalars do not have an intrinsic .Count property. By switching to a $null check and using the @() array subexpression, we ensure consistent behavior across PS 5.1 and PS 7+.

Related Issue

Fixes #223

Changes

  • Updated Get-IntuneWin32AppSupersedence.ps1 to handle scalar Graph responses.
  • Normalized relationship results into arrays to ensure .Count is always valid for logic and verbose logging.

Testing

Environment

Verified on:

  • Windows PowerShell 5.1 (Windows 11)
  • PowerShell 7.6

Output

The following code snippet shows the output of the execution in PowerShell 5.1, where the issue occurs.

PS C:\> Get-IntuneWin32AppSupersedence -ID "bcce6ee9-d839-46c3-b489-e6014345b7ef"
VERBOSE: Querying for Win32 app using ID: bcce6ee9-d839-46c3-b489-e6014345b7ef
VERBOSE: GET https://graph.microsoft.com/Beta/deviceAppManagement/mobileApps/bcce6ee9-d839-46c3-b489-e6014345b7ef
VERBOSE: GET https://graph.microsoft.com/Beta/deviceAppManagement/mobileApps/bcce6ee9-d839-46c3-b489-e6014345b7ef/relationships
PS C:\> # [No data returned, script stopped at the .Count check]

PS C:\patch\Public> . ..\Private\Invoke-MSGraphOperation.ps1
PS C:\patch\Public> . ..\Private\Test-AuthenticationState.ps1
PS C:\patch\Public> . .\Get-IntuneWin32AppSupersedence.ps1
PS C:\patch\Public> Get-IntuneWin32AppSupersedence -ID "bcce6ee9-d839-46c3-b489-e6014345b7ef"
VERBOSE: Querying for Win32 app using ID: bcce6ee9-d839-46c3-b489-e6014345b7ef
VERBOSE: GET https://graph.microsoft.com/Beta/deviceAppManagement/mobileApps/bcce6ee9-d839-46c3-b489-e6014345b7ef
VERBOSE: GET https://graph.microsoft.com/Beta/deviceAppManagement/mobileApps/bcce6ee9-d839-46c3-b489-e6014345b7ef/relationships
VERBOSE: Found 1 supersedence relationship(s)

# [Object Data Returned Successfully]

* Replaced .Count check with $null check for $Win32AppRelationsResponse to support scalar responses in Windows PowerShell.
* Applied @() subexpression to normalize $SupersedenceRelationships as an array, ensuring a valid .Count property.
* Updated Write-Verbose to utilize the guaranteed count of the normalized array.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get-IntuneWin32AppSupersedence fails to process single relationship in PowerShell 5.1

1 participant