List AAD Groups with membership count

Brian McCullough 1 Reputation point
2022-01-19T21:55:28.93+00:00

Is there a way to get a list of AAD groups with membership count? With Graph API? Even if ConsistencyLevel=Eventual?

Like: /groups?$filter=startsWith(displayName,'MYPREFIX-WHATEVS')&$select=displayName,members/$count

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,819 questions
{count} votes

2 answers

Sort by: Most helpful
  1. CarlZhao-MSFT 37,786 Reputation points
    2022-01-20T02:25:49.527+00:00

    Hi dear @Brian McCullough

    There is something wrong with your API, because members is actually an expansion item and not a child item, so your API should be changed to: /groups?$filter=startsWith(displayName,'MYPREFIX-WHATEVS')&$select=displayName&$expand=members.

    Since the expansion parameter $expand and the count parameter $count cannot be used together, your original API should remove the members parameter:

      GET https://graph.microsoft.com/beta/groups?$filter=startsWith(displayName,'MYPREFIX-WHATEVS')&$select=displayName,id&$count=true  
      ConsistencyLevel: eventual  
    

    Or only count the number of members of a certain group:

    https://graph.microsoft.com/beta/groups/{group object id}/members?$filter=startsWith(displayName,'MYPREFIX-WHATEVS')&$select=displayName,id&$count=true  
    ConsistencyLevel: eventual  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Brian McCullough 1 Reputation point
    2022-01-20T04:22:29.723+00:00

    Got it:

    $filter=startsWith(displayName,'MYPREFIX-WHATEVS')&$select=displayName&$expand=members($select=id,userPrincipalName,displayName)