How to distinguish Azure Active directory shared mailbox users and normal user via graph api?

Zakria Abbasi 20 Reputation points
2023-07-31T13:32:32.89+00:00

Hi, I am using Graph API to fetch Active directory users and the graph user object doesn't contain a property that can distinguish the real users from the shared mail box users.

My code:

 var res = await graphServiceClient.Users.Request().Header("ConsistencyLevel", "eventual").Filter("userType eq 'Member' and accountEnabled eq true")
                .Select("Id,DisplayName,JobTitle,Mail,BusinessPhones,MobilePhone,Department,streetAddress,GivenName," +
                "Surname,FaxNumber,CompanyName,City,PostalCode,Country,State,OfficeLocation")
                .Expand(expand).GetAsync();

The response I get contains all the users including the ones that were automatically created while setting up shared mail box. i:e from the following list of users I want to filter out the user with title "shared-mailbox" because it was automatically created when I set up the shared mailbox.

User's image

I will appreciate any help.

Thanks.

Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Answer accepted by question author
  1. Vasil Michev 123.7K Reputation points MVP Volunteer Moderator
    2023-07-31T15:50:06.4566667+00:00

    Best you can do via the Graph API is fetch the userPurpose property on the mailboxSettings resource, which gives you a clue whether the mailbox is user, shared and so on. However, that's one additional call for each user, and only covers mailbox recipient types, so it's incomplete. In other words, go with Andy's suggestion above and use the Exchange tools instead.

    Here's the relevant documentation on userPurpose: https://learn.microsoft.com/en-us/graph/api/resources/mailboxsettings?view=graph-rest-beta#userpurpose-values

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Andy David - MVP 159.7K Reputation points MVP Volunteer Moderator
    2023-07-31T14:19:24.9333333+00:00

    You wont be able to determine except via the Exchange Mgmt tools ( Exchange Powershell or the GUI)

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.