I am trying to filter out Guest
users in my Graph query. Since the ne
comparison operator is not supported I was trying $filter=userType eq 'Member' or userType eq null
instead. That fails too though. Any known workarounds to list users with null
as userType
?
Without that I need to download about a million rows each time and throw 4 out of 5 away on the client side, which is pretty slow and wasteful.
{
"error": {
"code": "Request_UnsupportedQuery",
"message": "Unsupported or invalid query filter clause specified for property 'userType' of resource 'User'.",
"innerError": {
"request-id": "411f7927-c3af-4042-a619-eee1c88971a0",
"date": "2018-03-17T18:28:35"
}
}
As a general rule of thumb, userType
should be either Member
or Guest
. The exception to this is when you're syncing an on-prem Active Directory. Since userType
is an Azure AD property, the value for a synced user will be null
.
If you can safely assume that your on-prem users are not guests, you can filter Azure AD user's based on if they're synced or cloud-native. You do this by looking at the onPremisesSyncEnabled
property. For synced users, this will be true
, for cloud-native users it will be null
.
If you combine this with the userType
property, you can effectively retrieve only non-guest users using the following $filter
:
$filter=onPremisesSyncEnabled eq true OR userType eq 'Member'
You can also avoid this entirely if you Enable synchronization of UserType in Azure AD Connect.
Update as of June 2021
the ne
comparison operator is now supported on userType on graph! So you can now get users that are not guest users with this query: https://graph.microsoft.com/v1.0/users/?$filter=userType ne 'guest'&$count=true
edit: Important to note that this is an advanced query as so it requires the header ConsistencyLevel
to be set to eventual
and include the $count=true query parameter
here is a link to graph explorer with the query that you can run
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With