Entra / Microsoft 365 · Teams
Report active Teams
Report active Teams by checking compliance records in associated Microsoft 365 Groups.
Connect & set up
Run these once per session. All scopes are read-only unless the script makes changes.
Connect-ExchangeOnline -ShowBanner:$false
Run it
The main script. Copy it, or download the .ps1 and run it from your console.
$Modules = Get-ModuleIf ("ExchangeOnlineManagement" -notin $Modules.Name) {Write-Host "Please connect to Exchange Online Management before continuing...";break}Write-Host "Fetching list of teams..."# $Teams = (Get-Team | Sort DisplayName)$Teams = Get-UnifiedGroup -Filter {ResourceProvisioningOptions -eq "Team"} -ResultSize Unlimited | `Select-Object Alias, ManagedBy, WhenCreated, GroupMemberCount, DisplayName, ExternalDirectoryObjectId | `Sort-Object DisplayNameWrite-Host "Starting to process" $Teams.Count "teams"$Count = 0; Clear-Host ; $GroupNumber = 0$Report = [System.Collections.Generic.List[Object]]::new()ForEach ($T in $Teams) {$ActiveStatus = "Inactive"$GroupNumber++$ProgressBar = "Processing team " + $T.DisplayName + " (" + $GroupNumber + " of " + $Teams.Count + ")"Write-Progress -Activity "Checking Teams for activity" -Status $ProgressBar -PercentComplete ($GroupNumber/$Teams.Count*100)# $G = Get-UnifiedGroup -Identity $T.GroupId | Select-Object Alias, ManagedBy, WhenCreated, GroupMemberCount, DisplayName, ExternalDirectoryObjectId$TeamsData = (Get-ExoMailboxFolderStatistics -Identity $T.ExternalDirectoryObjectId -FolderScope NonIpmRoot -IncludeOldestAndNewestItems | `Where-Object {$_.FolderType -eq "TeamsMessagesData"})If ($TeamsData.ItemsInFolder) {# Write-Host "Processing" $T.DisplayNameIf ($null -ne $TeamsData.OldestItemReceivedDate ) {$TimeSinceCreation = (New-TimeSpan -Start $TeamsData.OldestItemReceivedDate -End (Get-Date)).Days }Else {$TimeSinceCreation = "No compliance records found" }$Count++$ChatCount = $TeamsData.ItemsInFolder$NewestChat = $TeamsData.NewestItemReceivedDate} #End if# Calculate chats per day (only since Microsoft moved the compliance record location in October 2020)If ($ChatCount -eq 0) {Write-Host "No Teams compliance records found for” $T.DisplayName -foregroundcolor Red$ChatsPerDay = 0$NewestChat = "N/A"$ChatCount = 0 }Else {$ChatsPerDay = $ChatCount/$TimeSinceCreation$ChatsPerDay = [math]::round($ChatsPerday,2) }If ($ChatsPerDay -gt 0 -and $ChatsPerDay -le 2) { $ActiveStatus = "Moderate" }Elseif ($ChatsPerDay -gt 2 -and $ChatsPerDay -le 5) { $ActiveStatus = "Reasonable"}Elseif ($ChatsPerDay -gt 5) { $ActiveStatus = "Heavy" }$ReportLine = [PSCustomObject]@{Alias = $T.AliasName = $T.DisplayNameOwner = $T.ManagedByMembers = $T.GroupMemberCount"Date of team creation" = $T.WhenCreatedChatCount = $ChatCountLastChat = $NewestChat"Days for compliance records" = $TimeSinceCreationChatsPerDay = $ChatsPerDayActiveStatus = $ActiveStatus}$Report.Add($ReportLine)}Clear-HostWrite-Host $Count "of" $Teams.Count "have some Teams activity"$Report | Group-Object ActiveStatus | Sort-Object Count -Descending | Format-Table Name, count$Report | Export-CSV c:\temp\TeamsReport.csv -NoTypeInformation
Attribution
Author
Office365itpros