Skip to main content

Notifications

Generate Entra ID Groups and Users Report

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:

ManishSolanki_0-1720971882598.png

 

2. Next, add "List groups" action to get all office 365 groups:

ManishSolanki_1-1720971951205.png

 

3. Add "Apply to each" action to iterate o365 groups. Pass the value object from the output of "List groups" action as shown below:

ManishSolanki_2-1720972117921.png

 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:

ManishSolanki_3-1720972323855.png

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):

ManishSolanki_4-1720972507453.png

Click 'Switch Map to text mode' button on the right side:

ManishSolanki_5-1720972651029.png

Post that passes the display name dynamically as shown below:

ManishSolanki_6-1720972783425.png

Now, add "Compose" action to create object that holds the group name and members names:

ManishSolanki_7-1720972916513.png

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:

ManishSolanki_8-1720973165354.png

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:

ManishSolanki_9-1720973354608.png

concat(utcNow('yyyyMMdd_report'),'.csv')

Pass the output of "Create csv table" action in the attachment content parameter:

ManishSolanki_10-1720973466682.png

Save & click run to test the flow.

 

Output:

CSV file generated by flow after successful run:

ManishSolanki_11-1720973630124.png

 

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.

 

 

 

 

 

 

 

 

 

Comments

*This post is locked for comments