Seamlessly retrieve 1000+ members from a M365 group with Power Automate

The limit out-of-the-box on retrieving M365 Group members using the Office365 connector directly in your Power Apps is: 999.

When using Power Automate, we can turn on pagination and specify a threshold. But this threshold is not always working great, or the flow is running forever.

Scenario

We need to retrieve all the users from a M365 group (over a 1000), and send the response to Power Apps.

Power Automate

Because we’re interacting an app, our trigger is going to be Power Apps (no inputs needed). Then, let’s start by initialising the following variable:

  • varMembers = Array – We start with an empty array ([ ])

Now let’s get our members using the List group members action from the Office 365 Groups connector. Pick a group from the dropdown or enter a custom value with the Group ID and leave the Top option empty.

Make sure to enable pagination for this action by going to Settings -> Turn on pagination -> enter a number for the Threshold (i.e.: 2000) -> Click Done.

We can get the number of members with:

length(body('List_group_members')?['value'])

If you need members plus more details, a Select action will work, then pass it to Power Apps (using a Text input) with the Respond to a Power Apps or flow action.

The response needs a little bit of formatting, but we can take care of that directly into the app.

Power Apps

Into our app, we’re going to run our flow on the App.OnStart and store the results in a collection. Feel free to run your flow from whatever depending on your requirements. And don’t forget to connect your flow to the app!

ClearCollect(
    colM365GrpMembers,
    ForAll(
        Table(ParseJSON(Getover1000MembersinM365group.Run().members)),
        {
            DisplayName: Text(Value.DisplayName),
            Mail: Text(Value.Mail)
        }
    )
);

We use the ParseJSON() to format the response we get from Power Automate in a correct way, we use the .members property which is our output, and we specify the values we need (remember our Select action)

In my case, I’m going to Run OnStart, the flow will trigger in the background, and if I look at Variables –> Collections in the app, I can see that all my members are retrieved.

Thanks for reading! 🙂

Discover more from Veronique's Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading