Clean up your Teams with Help from Power Automate

Covid is near it’s end and we’re all trying to figure out how to go back to the office. Well if you’re like me then during Covid, a lot of Teams got created and there probably is a lot of users in the Teams that don’t need to be there. If you’re an admin of Office 365, then it isn’t hard to get a list from Azure AD to see the members.

But what if you’re not an Admin?

With a little help from Power Automate you can easily get a list of users to sort before dealing with the horrible user management in Teams.


If you’ve been using teams for a little bit you’re probably familiar with this screen…

Teams User Management

It’s pretty straight forward. The menu breaks up the Owners from the Members and Guests and it’s listed in the order the member was added to the team and there isn’t any sorting or exporting options either.

If your Team is only 10-20 people in size, this isn’t terrible to work with. But if you double that number or add a 1 or a 2 in front of this, then this would be terrible to work with.

Say hello to Power Automate to save you hours of work……

Power Automate to Save the Day!

Power Automate can pull a list of all the users for you that you can sort in excel in 3 easy steps.

Step 1. Get to Power Automate

Go to the Office 365 Portal and select Power Automate or go directly to Power Automate and sign in. Once you’re signed in, go to My Flows and click on New Flow and Select Instant Cloud Flow.

Creating a new flow.

Next, Give the flow a name and select Manually trigger a flow as the trigger and click Create.

Naming the Flow

Step 2. Building the Flow.

Click on + New Step button and search for List Group Members. The backend security mechanism for Teams is a Microsoft 365 group. Originally Microsoft 365 groups were called Office 365 groups. Microsoft’s rebranding hasn’t caught up yet in Power Automate.

Find the Group Id that has the same name as the Team you want to make the list for.

Select a Team

By default you can see the other members of groups you are a member of.

Select + New Step again and search for Create CSV and select Create CSV Table from Data Operations.

Now we have to feed the CSV some information.

The From field needs the value item from the Dynamic Content Menu. The value item includes all the contents of the entire group.
The Columns field can be left on Automatic and the CSV fields will include all the fields that were listed in the Dynamic Content Menu, First name, Last name, phone number, email, etc.

Creating the CSV Data

*Optional* If you want to scope the columns to make the list a little more specific, then choose Custom from the Columns drop down menu. Next, it’s as simple as typing in a header name and matching the Corresponding Dynamic Content.

Click + New Step when you’re done.

Scoped Columns

We’re almost done, we just need a place to store this information when it’s done. The easiest place is OneDrive for Business.

Search for Create File and select the one under OneDrive for Business.

Create File – OneDrive for Business

For Folder Path, make sure to click on the folder icon to get the folder structure of you’re OneDrive. If you miss the folder you’ll open the Dynamic Content Menu which wont get us any where. Select the location you want to store the files.
The File Name can be what ever you want it to be. Just make sure it ends in .csv so the file can be opened in excel. In the picture i used the utcNow() expression from the expression menu to timestamp the file. This is optional.

The last field is File Content. We have to tell power automate what to put in this new file. Select Output from the Create CSV Table section of the Dynamic Content Menu.

Create File Config

Click Save and you should be good to go. Other wise if there is any errors Power Automate is usually pretty good to tell you where they are.

Step 3. Run your Flow and Get your List

Running the flow can be done in the Power Automate Web Portal or In Teams if you add the Power Automate App to Teams.

Run your Flow.

Go back to the My Flows Section, Select your Flow and Click the Run button.

As you can see my flow took 4 seconds to run, this will take a little longer if it’s a large team.

Now that the flow has run successfully lets go open that file and take a look.

File In OneDrive
File in Excel


Now that you have your list, you can go and sort through it to find all the people to remove. Hopefully it’s a short list of people to find and remove. If not, maybe once you identify everyone that needs to be removed you can hand the list to your IT Department to more easily remove the extra people.

-Terry Sheridan