Carrying out a cleanup process from time to time helps against IT garbage. If you are an Microsoft 365 admin, the following post will help you to find out unused teams.
In large organizations, many teams are often created over time (which are not used). While Microsoft 365 now supports the cleanup with the renewal function (see more at Team expiration and renewal in Microsoft Teams), it is sometimes helpful to identify and evaluate teams that are no longer used and to carry out deletion actions yourself. The Microsoft Graph now offers a (beta) method for searching and identifying such teams according to your own criteria.
Identify Teams activity report
We can test this functionality very nicely with the Graph Explorer. Open aka.ms/ge. Currently, this only works with the getTeamsTeamActivityDetail method in the Beta endpoint (so, changes are possible in the future). The documentation reportRoot: getTeamsTeamActivityDetail informs about this report. The Microsoft 365 reports (like this) are updated within 48 hours. The parameter period='D90' stands for the last 90 days (see below).
https://graph.microsoft.com/beta/reports/getTeamsTeamActivityDetail(period='D90')
The user and app need to have the Reports.Read.All permission granted. The following screenshot shows the required permissions and the query result in Graph Explorer.
You get a list of all teams, when they were last used. Developers can use that method in PowerShell or other programming languages to get that data.
Particularities
There are a few points here that I would like to draw your attention to.
- As mentioned, this is currently only available in the beta endpoint. This means, the functionality could change in the v1.0 endpoint.
- You can add the desired result format in the query. Add ?$format=text/csv to create a CSV file, or ?$format=application/json for the (standard) JSON format
- The following period parameters are allowed: D7,D30,D90,D180, ALL (for going back 7 days, 30 days, etc.)
- The period parameter must be sent. If you submit ALL, you get a details array with all details per period (D7,D30,…,D180). This usually does not make sense, since the query always returns a list of all teams and their activity. Our recommendation here would be to select one parameter and to stick with it. Obviously, Microsoft copied another method using the period parameter and did not update this method. Let´s see if this will change in future.
- Paging works a expected: add the limit of items to read, like ?$top=100 and you get a next link for the following page (see below).
- From our perspective, the property isDeleted actually does not make sense. Soft-deleted groups are not included in the report, while teams that have set isDeleted to true seem to be hard deleted groups, where you cannot do (restore or look up) anything. Therefore, we recommend, to ignore such entries.
- This is important: If teams are returned with a TeamId "00000000-0000-0000-0000-000000000000", this means that the Microsoft 365 reports show anonymous data instead of actual data. You cannot use the this report properly because the teams are missing data, in particular the Team name. In this case, you should change the report settings as described below.
- The reports become available within 48 hours.
Run through all report data
Get the report with paging for larger data sets as here (and adapt the top parameter up to 100):
https://graph.microsoft.com/beta/reports/getTeamsTeamActivityDetail(period='D90')?$format=application/json&$top=2
Follow the @odata.nextLink to get the next page, like in this sample.
The lastActivityDate shows when the team was last accessed.
Turn off obfuscation
If you get a report with TeamId´s "00000000-0000-0000-0000-000000000000", switch off the obfuscation feature in the Microsoft 365 admin center settings. Only a M365 Global Admin can do this. Go to Settings - Org Settings - Services and select Reports in the list.
Clear the Display concealed user, group, and site names in all reports switch and click Save, as here. You can find more about the M365 reports at Microsoft 365 Reports in the admin center.
This switch works instantly. You can then try the graph request operation again. You should then get your real data.
I hope this article helps to programmatically get more information about Teams usage in your Microsoft 365 tenant.