Skip to content

Get-IntuneWin32AppAssignment (v1.5.0) returns an assignment entry even when app has none #206

@obuolinis

Description

@obuolinis

When app has no assignments:

  • Get-IntuneWin32AppAssignment v1.4.4 returns nothing, just a warning "WARNING: Empty response for assignments for Win32 app:"
  • Get-IntuneWin32AppAssignment v1.5.0 returns 1 assignment entry with all fields empty, except app name.

The problem seems to be in this line:

if ($Win32AppAssignmentResponse -ne $null -and $Win32AppAssignmentResponse.Count -gt 0) {

You should be checking $Win32AppAssignmentResponse.value.Count rather than $Win32AppAssignmentResponse.Count :)

UPDATE: Ok, not that simple it seems.
The problem is that Invoke-MSGraphOperation seems to produce different type of PSCustomObject when the app has no assignments, not what Get-IntuneWin32AppAssignment expects - one with two properties @odata.type and value, which is empty. And therefore Get-IntuneWin32AppAssignment thinks it has 1 assignment to process.

Such object seems to be a raw output of Invoke-RestMethod which you use for Invoke-MSGraphOperation.

How does it escape like this?

As far as i understand, in this response processing block you expect all/empty responses to have @odata.count property which in this case the response doesn't have, therefore it gets processed incorrectly.

if ($GraphResponse.'@odata.nextLink' -ne $null) {
$GraphResponseList.AddRange($GraphResponse.value) | Out-Null
$GraphURI = $GraphResponse.'@odata.nextLink'
Write-Verbose -Message "NextLink: $($GraphURI)"
}
else {
# NextLink from response was null, assuming last page but also handle if a single instance is returned
if ($GraphResponse.value) {
$GraphResponseList.AddRange($GraphResponse.value) | Out-Null
}
elseif ($GraphResponse.'@odata.count' -eq 0) {
# Do nothing to return empty
}
else {
$GraphResponseList.Add($GraphResponse) | Out-Null
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions