azure active directory – How to get Open Extensions properties of All Group Members using Microsoft Graph SDK in a single Get command

In Azure Active Directory, While creating a user in Azure AD, I’m adding Extention data for each users using the OpenTypeExtension

Below is the snippet which is being used to add Extention data to each user while creating a new user in Azure AD.
Here, I’m adding three Extension properties to each users namely (acsid, defaultgroupid and useryominame)

var openTypeExtension = new OpenTypeExtension();
                openTypeExtension.ExtensionName = "com.mysite.user.extprofile";
                openTypeExtension.AdditionalData = new Dictionary<string, object>();
                openTypeExtension.AdditionalData.Add("acsid", "8:acs:0e9c3151-234r-4e5b-3245-37ffaa4d79ab_00000017-2erf-75bc-8876-c93a0d00abcd");
                openTypeExtension.AdditionalData.Add("defaultgroupid", "347e12e4-9cf1-437b-f4r5-6dcc7452234d");
                openTypeExtension.AdditionalData.Add("useryominame", "myyominame");

var extensionresult = await _graphClient.Users[user.Id].Extensions["com.mysite.user.extprofile"].Request().GetAsync();

Now, once the user is created and respective extensions properties (acsid, defaultgroupid and useryominame) is also added to the user in Azure AD.

But, when I try to fetch all the Group members using Microsoft Graph SDK, the list of users/members does not returns ‘extensions‘ properties (acsid, defaultgroupid and useryominame).

Below is the code snippets to get the Group members.

GraphServiceClient graphClient = await GetGraphClient()
                    .ConfigureAwait(false);

                var groupMembers = await graphClient.Groupstag:google.com,2013:googlealerts/feed:11402335752437993429.Members
                    .Request()
                    .GetAsync()
                    .ConfigureAwait(false);

                var usersInGroup = groupMembers.OfType<User>().ToList();

In the above code snippets variable usersInGroup does not contains extensions properties (acsid, defaultgroupid and useryominame)

So, after getting the usersInGroup list, I had to iterate each user from the list and then get the Extension properties.

Below is the code where I’m using for-loop to iterate through each users and then Get the Extensions properties for each users.

Note: Here, I’m using Parallel.ForEach instead of simple foreach to optimize my response time.

Parallel.ForEach(usersInGroup, user =>
                {
                    var userWithExtensions = graphClient.Users[user.Id].Extensions["com.mysite.user.extprofile"].Request().GetAsync();
                    user.AdditionalData = userWithExtensions?.Result.AdditionalData;
                }
                );

I’m thinking, If Microsoft Graph SDK provide any options where we can get the Extensions directly while getting the Group Members.

Read more here: Source link