How to get group display in response when listing group members using graphapi. To know user to group mapping

WMS_Dev_user1 20 Reputation points
2023-10-18T09:28:10.4933333+00:00

I am trying to fetch a list of users that belongs to specific groups. But in the response payload i wish to get the group details as for mapping in my application.

Thanks in advance,

Naveen

Microsoft Security | Microsoft Graph
{count} votes

Answer accepted by question author
  1. CarlZhao-MSFT 46,406 Reputation points
    2023-10-27T09:41:48.84+00:00

    Hi @WMS_Dev_user1

    Based on my testing, it seems that it is not possible to filter the set of users by given some group ids. The possible way is through the Graph SDK.

    var users = await graphClient.Users.GetAsync((requestConfiguration) =>
    {
        requestConfiguration.QueryParameters.Expand = new string[] { "memberOf" };
    });
    
    
    foreach (var user in users.Value) {
    
        foreach (var group in user.MemberOf) {
       
            if (group.Id is "{group1 id}" or "{group2 id}" or .......) {
    
                Console.WriteLine("user id: " + user.Id + "\r\n" + "user name: " + user.UserPrincipalName + "\r\n"+ "group id: " + group.Id);
    
                Console.WriteLine("------");
    
          
            }
        
        }
    
    }
    

    User's image

    Of course, if anyone has a better solution for this, please feel free to share.

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. WMS_Dev_user1 20 Reputation points
    2023-10-26T17:31:30.7766667+00:00

    Any updates regarding my query ?

    0 comments No comments

  2. WMS_Dev_user1 20 Reputation points
    2023-10-27T13:04:39.66+00:00

    Thanks for your prompt reply.

    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.