Search code examples
powershellmicrosoft-graph-apimicrosoft-entra-id

Microsoft Graph User Lambda Filter with two statements


I'm trying to get all users in Entra ID that do NOT have an ENABLED Entra ID P1 license.

I am starting with the opposite which I just have to negate in the end. So for now, I'm trying to collect all users with an enabled Entra ID P1 license. This is what I've figured out so far:

All users with an Entra ID P1 license, whether it's enabled or not:

Get-MgUser -Filter "assignedPlans/any(a:a/ServicePlanId eq 41781fb2-bc02-4b7c-bd55-b576c07bb09d)" -ConsistencyLevel eventual -CountVariable eidp1count

All users with an Entra ID P1 license and any random enabled license:

Get-MgUser -Filter "assignedPlans/any(a:a/ServicePlanId eq 41781fb2-bc02-4b7c-bd55-b576c07bb09d) and assignedPlans/any(a:a/capabilityStatus eq 'Enabled')" -ConsistencyLevel eventual -CountVariable eidp1count

What I actually need is something along the lines of this:

Get-MgUser -Filter "assignedPlans/any(a:a/ServicePlanId eq 41781fb2-bc02-4b7c-bd55-b576c07bb09d and a:a/capabilityStatus eq 'Enabled')" -ConsistencyLevel eventual -CountVariable eidp1count

I know I can filter more with Where-Object in Powershell but that won't do me good when I need to negate the query to get to my initial goal.


Solution

  • As most of the time: enlightenment comes after pressing 'post your question'.

    Answer is:

    Get-MgUser -Filter "assignedPlans/any(a:(a/ServicePlanId eq 41781fb2-bc02-4b7c-bd55-b576c07bb09d and a/capabilityStatus eq 'Enabled'))" -ConsistencyLevel eventual -CountVariable eidp1count
    

    And to negate it

    Get-MgUser -Filter "not(assignedPlans/any(a:(a/ServicePlanId eq 41781fb2-bc02-4b7c-bd55-b576c07bb09d and a/capabilityStatus eq 'Enabled')))" -ConsistencyLevel eventual -CountVariable eidp1count