Remove User from all SharePoint Groups with Power Automate
In this article I will describe how to use Power Automate in order to remove a user from all SharePoint Groups of a specific site, the user is member of.
All actions for doing this:
- Get UserId of user from Mail
- Get Groups of the user
- Remove the user
Starting point is the mail address of the specific user. You can think about using PowerApps Trigger and pass a mail within the parameter, use a manually trigger orβ¦. It is up to you π at the end we just need the Mail address.
Get UserId of user
Simple SharePoint HTTP call is doing this job. We store the id of the output into a variable.
Call: _api/web/SiteUsers/getByEmail(‘@{variables(‘mail’)}’)
Get Groups of the user
Now just safe the flow and run a test to get the output body of the HTTP call.This should be used to parse the json (Generate by sample, the sample in that case is the body). Step by step:
- Run a test
- Copy the output (body)
- Edit flow
- Insert parse json action
- Click on button Generate from sample
- Paste body here
- Save
- Test
- You can use the variables π
We need the iterate though all group IDs and store it in an array.
Call: _api/web/GetUserById(@{variables(‘userid’)})/Groups
Id: @{items(‘Apply_to_each_Group_store_ID’)?[‘Id’]}
Remove the user
Last step is to simply iterate through all elements of the array and remove the user with a SharePoint HTTP call.
Call: _api/web/sitegroups(@{items(‘Apply_to_each’)})/users/RemoveByID(@{variables(‘userid’)})
Example Flow