hlaliberte
hlaliberte

Reputation: 99

How to fetch group memberships from an AAD group

I'm trying to fetch all group memberships from an AAD. I have to name of the parent group I want to look for, but I need to fetch the users that are in sub groups of that parent. I've tried may things on the Microsoft docs, but I can't find the right request to find those groups.

This is a try:

var groups = await graphClient.Groups.Request().Filter($"startswith(displayName, '{Se_groupName}')").GetAsync(); //Fetch the parent group
var groupMembers = await graphClient.Groups[groups.FirstOrDefault().Id].Members.Request().GetAsync(); //Try to fetch the groups inside the first group, but its always empty

I was wondering is there a request like:

graphClient.Groups[groups.FirstOrDefault().Id].groupMemberships

Upvotes: 1

Views: 941

Answers (1)

scottwtang
scottwtang

Reputation: 2040

To find the nested groups and users you can use the transitiveMembers endpoint

List group transitive members

GET https://graph.microsoft.com/v1.0/groups/{groupId}/transitiveMembers

Upvotes: 2

Related Questions