title: Get Users in Group from Azure AD via Microsoft Graph
body: <p>I'm requesting a list of users from AzureAD via Microsoft Graph.</p>
  
  <p>I get the User objects back, but their MemberOf property is always null.</p>
  
  <p>I thought I could use Expand to request that property specifically, and while it causes no error it also doesn't populate the property.</p>
  
  <p>This <a href="https://stackoverflow.com/questions/39004373/microsoft-graph-list-all-users-and-their-groups-in-one-request">question and answer from mid-2016</a> suggests this functionality was in beta at that time, and I thought it would have graduated to the production API by now?</p>
  
  <pre><code>var allUsers = await graphClient
      .Users
      .Request()
      .Expand("memberOf")
      .GetAsync();
  
  var usersInGroup = allUsers
      .Where(user =&gt; user.MemberOf.Any(memberOf =&gt; memberOf.Id.Equals(groupId, StringComparison.OrdinalIgnoreCase)))
      .ToList();
  </code></pre>
  
  <p>(I've tried expanding "memberOf" and "MemberOf".)</p>
  
  <p>I can retrieve a list of members via the Group.</p>
  
  <p>But that returns a list of IDs, so I'd have to make two requests instead of just the one.</p>
  
  <pre><code>var groupMembers = await graphClient
      .Groups[groupId]
      .Members
      .Request()
      .GetAsync();
  
  var groupMemberIds = groupMembers
      .Select(groupMember =&gt; groupMember.Id)
      .ToList();
  
  var allUsers = await graphClient
      .Users
      .Request()
      .GetAsync();
  
  var usersInGroup = allUsers
      .Where(user =&gt; groupMemberIds.Contains(user.Id))
      .ToList();
  </code></pre>
  
  <p>If getting the IDs belonging to the Group, and then filtering the Users is the correct way then that's fine, I'll go with that.</p>
  
  <p>Ideally I'd like to make a single request to retrieve the User objects and have the filtering done server side.</p>
  
  <p>e.g.</p>
  
  <pre><code>var usersInGroup = await graphClient
      .Users
      .Request()
      .Filter($"memberOf eq {groupId}")
      .GetAsync();
  </code></pre>
  
  <p>Obviously that filter won't work, but something like that would be ideal.</p>
  
  <p><sup><sub>(It was pointed out that I have been linking to the wrong set of documentation, so I've stripped out those links to prevent confusion for future readers)</sub></sup></p>