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:
Get-MgUser -Filter "assignedPlans/any(a:a/ServicePlanId eq 41781fb2-bc02-4b7c-bd55-b576c07bb09d)" -ConsistencyLevel eventual -CountVariable eidp1count
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
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.
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