Power Automate: Add owner to M365 Group

Ok. So I had a scenario in which I needed to cycle through SharePoint project sites and remove all of the owners and members to essentially mark the sites as Read-Only. I created Power Automate Flows to do both the “closing” and the “reopening” processes. However, the Reopening process needed to include adding the Project Manager from the master projects list into the Owners group. Therefore, I needed to leave the service account in the Owners group as well to facilitate the reopening process.

The Problem:

My personal account was an owner in all project sites, but the service account didn’t start getting added as an owner until after we had created the first 300 sites. So I needed to add the service account as an owner before I could use the service account’s SharePoint connection to remove owners and members automatically. After some googling, I found Tom Rhia’s post on how to get the list of owners of a group. https://tomriha.com/how-to-get-microsoft-365-group-owners-in-power-automate/ I then added a condition to check if the service account was in the list of owners. If it was not, then I used another post to locate the Send an HTTP Request action required for adding the user to the AD Group’s Owners list. And I added a 15 second pause afterward for Microsoft’s processes to run. Unfortunately, I kept getting errors when I tried to run the Flow. That’s really what this post is about.

More than 1 HTTP Request action

During the steps, I read to use an HTTP Request action. When I neglected to notice is WHICH HTTP REQUEST action to use. There are multiple options. When I type HTTP Request into the search, I get 3 options. None of which is the one I need.

Once I realized my mistake, I clicked on Groups and saw the correct HTTP Request action.

From there, I just followed the two blog posts and everything went well. Kinda… Because my personal account was an owner, and I needed to add the service account, I had to switch the connection on the HTTP Request to my personal account. (I also made a note to any future developers that they would need to update the solution in my absence.) It should be fine now. I would run the workflow as the service account, if the service account was not in the Owners list, then I’d use my personal account to add it, and then move forward with the service account removing Owners and Members. Except the HTTP Request action kept erroring saying “Insufficient Privileges”. I ended up running the Flow as my personal account but keeping the service account for the updates to the Groups and to the SharePoint List Items.

I hope this helps someone out there. Good luck, and may the odds be ever in your favor.

Categories Uncategorized
Design a site like this with WordPress.com
Get started
search previous next tag category expand menu location phone mail time cart zoom edit close