Get the latest Teams activity with Graph

2022-05-11 | Martina Grom

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.

image

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.

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.

image

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.

image

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.

image

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.

Categories: Cloud, Developer, English, Graph, Microsoft, Microsoft365, Office365, Tools

Source: https://blog.atwork.at/post/Get-the-latest-Teams-activity-with-Graph