Use Case:
This flow will export all Entra ID groups with members details in csv format. It will share the csv file in an email to admin or concerned person.
Solution:
1. Create a schedule flow that generates report on schedule basis. Please set up the recurrence frequency, time zone & start time as per your need. Here, I have set to run it once a month at 9 am:
2. Next, add "List groups" action to get all office 365 groups:
3. Add "Apply to each" action to iterate o365 groups. Pass the value object from the output of "List groups" action as shown below:
Inside "Apply to each" block, add "List group members" action to get the members of each group. Pass the 'Group Id' dynamically from the output of "List groups" action:
Add "Select" action to create an array of display name of members of a group. Pass the value object from the output of previous action (List group members):
Click 'Switch Map to text mode' button on the right side:
Post that passes the display name dynamically as shown below:
Now, add "Compose" action to create object that holds the group name and members names:
Just copy & paste below code in compose action textbox:
{
"Name": @{items('Apply_to_each')?['displayName']},
"User(s)": @{concat('"', join(body('Select'), ', '), '"')}
}
4. Outside of "Apply to each" block, add "Create csv table" action to convert compose array in csv format. Enter an expression to pass the value of compose action. Expression needs to be added in expression box as shown below:
outputs('Compose')
5. Finally, add "Send an email" action to share the csv report. Set the recipient, subject & email body as per your need. Enter an expression to generate name of csv file:
concat(utcNow('yyyyMMdd_report'),'.csv')
Pass the output of "Create csv table" action in the attachment content parameter:
Save & click run to test the flow.
Output:
CSV file generated by flow after successful run:
Conclusion:
We can use "List groups" and "List group members" action to get the group & member names. With the help of "Select" action we can create array of custom object. This array can be transformed to csv data using "Create csv table" and finally shared as an attachment in an email for reporting purpose.
*This post is locked for comments