Power Automate to monitor group membership

Office 365 Groups, Office 365 Users, and Microsoft Teams
Office 365 Groups, Office 365 Users, and Microsoft Teams connection

In this post, I am going to show you how I can identify new or recently removed members in a 365 Group.

Why did I need this?

After managing a learning community Team for the last several months I found myself asking the recently departed members why they left. Typically, I would chat message them in hopes they can give me constructive criticism and feedback for improvement; a manual process.

The Goal

Automate the identification of recently removed members within my 365 Group so I can then follow-up with them programmatically.

Power Automate Connectors

In this example, I will be using:

  1. Office 365 Groups – https://docs.microsoft.com/en-us/connectors/office365groups/
  2. Office 365 Users – https://docs.microsoft.com/en-us/connectors/office365users/
  3. Microsoft Teams – https://docs.microsoft.com/en-us/connectors/teams/

Office 365 Groups

When creating an Automated flow, you need an event trigger. Learn how to Create a flow in Power Automate @ https://docs.microsoft.com/en-us/power-automate/get-started-logic-flow. This connector has the trigger event When a group member is added or removed which is exactly what we are looking for.

The only required field for this trigger ‘Group Id’.

The values that are returned from this trigger are:

  • UserID
    • I will use this in Office 365 Users > Get User Profile (V2)
  • Reason
    • I will use this in the conditional boolean logic action

Microsoft Teams

I used the Get a team action simply to be able to retrieve ‘Display Name’ of the Team which the event is occurring on. This allows me not to hard-code this value later.

Office 365 Users

I find myself using this connector often. What I have found is that helpful values like ‘Display Name’ and ‘Mail’ are pretty much essential to making dynamic personalized flows like this.

Learn how to Add multiple actions and advanced options to a flow @ https://docs.microsoft.com/en-us/power-automate/multi-step-logic-flow.

The order of these actions is inconsequential as they are GETS.

For our needs, we can describe these actions as:

I use the dynamic User Id content from the trigger event

Conditional Logic

Using a boolean on the return value from the trigger (Reason) I can have two different outcomes; a member was added or a member was removed.

If true then x else y

The empty() Expression

empty(triggerBody()?['@removed']?['reason'])

I was not able to find the documentation on returned values for ‘reason’. I took a gamble and assumed that if there was not a reason (it was empty) then that must mean they have been added to the Team.

The true Expression

Make sure to use the Expression editor rather than the text string ‘true’.

Output from the Conditional Logic

As you can see, I am sending a message as the flowbot to a user within Teams. As this is an example, it is easiest to test by sending myself a message using the dynamic content from ‘Get my profile (V2)’.

It is at this point that you get to decide what happens. Do you want to introduce yourself to the new member via email? Do you want to send a hyperlink to an MS Form with questions about why someone left?

The Result

For our example, I send a dynamically generated message to myself in Teams.

A simple dynamic message from the Flow bot

2 thoughts on “Power Automate to monitor group membership”

  1. Thank you so much! Even the template provided by Microsoft was wrong, and all the messages posted by other users were incorrect. I realized looking at the input body that I needed to check for empty reason, but I didn’t know how to do it. Your code works perfectly. It is a shame that MS has not documented in an easy to find location all the possible values for reasons and code samples to check for the values. I used to be a developer a long time ago, so I’m not in touch with the current language semantics. Your post saved me!

    1. I agree. It is a shame that it is not documented. Great to hear I was able to help you out!

Leave a Reply

Your email address will not be published. Required fields are marked *

css.php