In my last blog post, I showed you how to find inactive Microsoft Teams with GraphAPI and Azure Automation. I’ve blogged about a script that writes all inactive Microsoft 365 groups to a SharePoint Online list. In this blog post, I will show you, how to archive inactive Microsoft Teams with Azure Automation.
My solution uses an approval process by Microsoft Flow and a Azure Automation Account with a scheduled script to archive a Team. The script uses the GraphAPI endpoint.
Why we should archive a Microsoft Teams
When a project is completed and we don’t need the Microsoft Teams created for this project anymore, we can delete the Team. But of course, this means that all data stored in this Team, all the conversations, Planner activities and notes and so on are deleted, too. But what if these data are business critical and are still needed in a few months or years? So, what is a better option for inactive Teams?
A better way would be to archive the Team. It is quite easy and every Team’s owner can archive a Microsoft Team. When you archive a Team, it becomes read-only for the members, but it is still accessible for them. The Teams owner can still modify the Teams. Also, the Microsoft Teams client sorts archived Teams at the end of the Teams list.
Another big advantage of an archived Team: the owner itself can reactivate the Teams. The owner does not need to call the IT for this task. The owner can reenable the Team by the same way the Team was archived. So, it’s a straightforward process.
Of course, Microsoft provides a way to use the GraphAPI for archiving a Microsoft 365 group and I use it in my script. Now, let’s start how to archive inactive Microsoft Teams with Azure Automation.
Archive a M365 group by GraphAPI
To archive a M365 group, you just need to call the GraphAPI endpoint
Even though the Microsoft learning article mentions that you need to use a request body to make the corresponding SharePoint site read-only, this is not necessary for our scenario here and is not supported. Nevertheless, team member cannot upload new files, modify existing ones, etc.
Your Managed Identity requires the GraphAPI permission TeamSettings.ReadWrite.All. And of course, you can find a script in my GitHub Account for these purposes.
Start an approval process before archiving a Teams
It’s always a clever idea to ask the Teams owner, before an automation starts to archive it. The easiest way is to start an approval process by Power Automate. The updated SharePoint Online list element triggers a Microsoft Flow and starts an approval process.
The advantage of approval process in Microsoft Flow is the usability:
The approval sends a mail to the user and an approval notification to the Teams activity feed. You can find the pending approval in the approval app in Teams, and in the Flow app.
The approval process includes all owners of a Team and a response from a single owner is enough to start the archive function.
This basic Microsoft Flow is executed when an inactive team is found and added to the SharePoint Online list by the script from the first blog post. Of course, I have set a trigger condition so that the Flow is only executed when the “Should be archived” column is true.
On the right side of the Flow, you can see the approval path. When an owner of a team sends a response to the approval, the flow updates the SharePoint Online list element with the response. Normally, you can stop the flow already at that point.
Here, in this screenshot, you find some other ideas like a condition to run different actions based on the result. At the end, the flow is terminated successfully.
On the left side, you see an uncomplicated way to implement a friendly reminder. If the approval is still pending, the flow sends a mail after 24 hours. And a second reminder after another 24 hours. At the end, the flow terminates as failed because an approval is missing. Of course, you can extend the flow by sending a mail to the IT stuff in that case, for example.
Combine the approval result with Azure Automation
The last step is to schedule the Azure Runbook that starts the archiving process of a Team. The Runbook get all items of the SharePoint List, filters the items and archives only new list items where the owner has approved to archive.
New is the option to schedule the monthly occurrences to last day of a month or on weekdays like every last Sunday of a month. These are good and cool improvements.
Visit my GitHub site to find all required scripts.