“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']}"
}
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.
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']}"
}
The whole flow diagram
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.
Hi,
Is there a simply flow to add and delete members into Teams private channel whilst at the same time members remain in the Teams group channel.
Thanks.