Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Triggers
  • Resources
  • ABOUT ME
  • Get help with your flow
Menu

Remove member from Teams private channels in Power Automate

Posted on March 8, 2023March 8, 2023 by Tom

“Can I use Power Automate to remove user from all private channels in a Team, even if I don’t know whether he’s a member?”


Teams private channels are not the easiest thing to manage. Unlike the Office 365 groups connected to Teams, members of private channel are much more hidden. If you want to remove them, you must go channel by channel. Or you can build a flow that’ll do it for you. A single flow to go through all channels in a team and remove the specific user (if found).

You’ll need a registered app in Azure

Since such operation is not possible using the standard actions, you’ll need an HTTP request. A request sent by the premium HTTP action to Graph API that’ll do the work for you. But to make it a bit more complicated, you’ll need a registered app in Azure first as explained in the previous article.

Follow the same steps as in the previous article until you reach the ‘List channels’ action.

For this article you’re interested only in the private channels – filter them out using the ‘Filter array’ action.

@equals(item()?['membershipType'], 'private')

Now, with only the private channels, you can start adding the HTTP requests. Firstly, authenticate using the registered application (the url and content are in the previous article).

Loop through all the private channels and get their members.

Method: GET

Uri:
https://graph.microsoft.com/v1.0/teams/@{items('Apply_to_each')?['id']}/channels/@{items('Apply_to_each_2')?['id']}/members

Headers:
{
  "Content-Type": "application/json",
  "Authorization": "Bearer @{body('HTTP_-_Authenticate')?['access_token']}"
}
Power Automate remove member private channels

Using the ‘Filter array’ check whether the user is among the team members – filter only users with the specific email. That should give you 0 to 1 results.

Add another ‘Apply to each’ and use the filter outcome as the input. The benefit of such solution is that you don’t need to check whether there’re any results. If the user is among the members, the loop will run once. If he’s not in there, the loop will skip all the actions inside and do nothing.

Power Automate remove member private channels

All that’s let if to remove the user from the channels.

Method: DELETE

Uri:
https://graph.microsoft.com/v1.0/teams/@{items('Apply_to_each')?['id']}/channels/@{items('Apply_to_each_2')?['id']}/members/@{item()?['id']}

Headers:
{
  "Content-Type": "application/json",
  "Authorization": "Bearer @{body('HTTP_-_Authenticate')?['access_token']}"
}
Power Automate remove member private channels

The whole flow diagram

Power Automate remove member private channels

Summary

As you can see, the Power Automate flow that’ll go through all private channels and remove a specific member isn’t that complicated. Get the team, list the channels, check if the user is among the members and if is, remove him. The most complicated part are the HTTP requests to Graph API and the app registration, but if you follow the steps in this and the previous article you should be fine.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Leave a Reply Cancel reply

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

Do you know what to do, but not how to do it?

Get The Ultimate Power Automate expressions cheat sheet and translate your thoughts into flows with ease!


There's also the HTTP requests to SharePoint cheat sheet to help you overcome limitations of some standard actions!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

  • How to find Excel rows missing in SharePoint list (Power Automate)March 29, 2023
  • Check whether user exists in AAD with Power AutomateMarch 26, 2023
  • How to highlight whole SharePoint row based on calculated dateMarch 22, 2023
  • Why is your Power Automate flow running so slow?March 19, 2023
  • How to add multiple links to the Power Automate approval taskMarch 15, 2023

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes