Back to script library
Entra / Microsoft 365 · Teams

Report teams activity data

Report the Teams usage data using the Microsoft Graph PowerShell SDK.

Connect & set up

Run these once per session. All scopes are read-only unless the script makes changes.

Connect-MgGraph -Scopes ReportSettings.ReadWrite.All

Run it

The main script. Copy it, or download the .ps1 and run it from your console.

Connect-MgGraph -Scopes ReportSettings.ReadWrite.All
Select-MgProfile Beta
# first, find if the data is obscured
$Display = Invoke-MgGraphRequest -Method Get -Uri 'https://graph.microsoft.com/beta/admin/reportSettings'
If ($Display['displayConcealedNames'] -eq $True) { # data is obscured, so let's reset it to allow the report to run
$ObscureFlag = $True
Write-Host "Setting tenant data concealment for reports to False" -foregroundcolor red
Invoke-MgGraphRequest -Method PATCH -Uri 'https://graph.microsoft.com/beta/admin/reportSettings' -Body (@{"displayConcealedNames"= $false} | ConvertTo-Json) }
$Uri = "https://graph.microsoft.com/beta/reports/getTeamsTeamActivityDetail(period='D180')?`$format=application/json&`$top=999"
[array]$Data = Invoke-MgGraphRequest -Uri $Uri -Method Get
$Data = $Data.Value
If ($Data.Count -gt 0) {
$Report = [System.Collections.Generic.List[Object]]::new()
ForEach ($Team in $Data) {
$ReportLine = [PSCustomObject][Ordered]@{
Name = $Team.teamName
LastActivity = $Team.lastActivityDate
AccessType = $Team.teamType
Id = $Team.teamId
IsDeleted = $Team.isDeleted
ActiveUsers = $Team.Details.activeUsers
ActiveExtUsers = $Team.Details.activeExternalUsers
Guests = $Team.Details.guests
ActiveChannels = $Team.Details.activeChannels
SharedChannels = $Team.Details.activeSharedChannels
Posts = $Team.Details.postMessages
Replies = $team.Details.replyMessages
Channelmessages = $Team.Details.channelMessages
Reactions = $Team.Details.reactions
Mentions = $Team.Details.mentions
UrgentMessages = $Team.Details.urgentMessages
Meetings = $Team.Details.meetingsOrganized
}
$Report.Add($ReportLine) }
}
$Report | Out-GridView
# And reset obscured data if necessary
If ($ObscureFlag -eq $True) {
Write-Host "Resetting tenant data concealment for reports to True" -foregroundcolor red
Invoke-MgGraphRequest -Method PATCH -Uri 'https://graph.microsoft.com/beta/admin/reportSettings' -Body (@{"displayConcealedNames"= $true} | ConvertTo-Json) }
Attribution