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

Leave a Reply

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