Comparing the members of a distribution list to the members of an Office 365 group or Team
Hello everyone, cycling through members of a distribution list and comparing them to the members of another group is a relatively simple thing to solve in PowerShell but took me some time to wrap my head around in Power Automate.
Below, I broke the process down into multiple steps. The end goal of this project is to be able to detect new members of a distribution list and perform specific actions for those new users such as adding them to a team, send them a custom email or so many other possibilities.
In the use case below, my objective is to analyze the members of a distribution list which is populated by an HR process and automatically add new members to a specific Team, and send them a custom welcoming email with details.
Create the flow
|
| ||||
Get the distribution list [DL] members
I suggest renaming the action to something more obvious like “Get Distribution List Members” instead of the default “Get group members”. This will help with the flow later. |
| ||||
Initialize a variable to store the DL members
|
| ||||
Append the DL members to the variable
Important note: This action will list all distribution list members. This includes all nested groups. To detect a nested group, you will need additional steps. These will be outlined in a future post. Note: Again, as suggested previously it would be easier if you rename the actions above. See screenshot below, for example. I renamed “Apply to each” to “Foreach DL Member append ID to DLMembers” and “Append to array variable” to “Append to array variable DLMembers”.
|
| ||||
Get the current Team or O365 Group members
Note: Now, keep in mind some of the limitations for Teams or O365 Groups. There can only be a maximum of 10,000 members in a Team. https://aka.ms/AAactar This function allows only listing a maximum of 999 members.
|
| ||||
Add a new variable for Team Members
|
| ||||
Append the Team members to the variable
|
| ||||
Run the comparison and do stuff
|
|
Here is an image of the entire flow:
I hope this proves useful.
Comments
-
Comparing the members of a distribution list to the members of an Office 365 group or Team
I tried to modify this to make a Mail Enabled Security Group match a dynamic Microsoft 365 group. From the outputs I can see it finds everyone but when it comes to adding the missing user it says it completed but I don't see a difference.
Azure Members is my Microsoft 365 group that is dynamic and MESG is the mail enabled security group that I want to match the Azure group.
-
Comparing the members of a distribution list to the members of an Office 365 group or Team
Pardon my ignorance, but is an Office 365 distribution list the same as an Outlook distribution list. I have been trying to find a way to use Power Automate to get the names of all members of an MS Outlook distribution list
-
Comparing the members of a distribution list to the members of an Office 365 group or Team
So awesome - I'm still impressed you got this worked out so quickly lol
*This post is locked for comments