TopBanner

Microsoft Teams: Use PowerShell to Check for Unused Teams Based on Chat Activity from Administrator Perspective

image

This below script shows Teams statistics from an Administrator’s point of view using Exchange Online PowerShell.


Log In to Exchange Online with PowerShell

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication  Basic -AllowRedirection
Import-PSSession $Session


Put Exchange Groups with Microsoft Teams “Team Chat” Folders into an Object

The below PowerShell will look for all the “UnifiedGroups” that have a Microsoft Teams chat folder in them (effectively groups that are Microsoft Teams Groups) and put them into an object. Note: This PowerShell will take a while to run, even on a small Office 365 tenant.

$TeamsStats = Get-UnifiedGroup | Get-MailboxFolderStatistics  | ? {$_.Name -eq “Team Chat”}

Now you can see which teams are new and active to run clean up procedures you want. Below are some examples:

Get Teams With No Chat Activity for Last 90 Days


$TeamsStats | ? {$_.LastModifiedTime -lt (get-date).AddDays(-90)} | Format-Table Identity, Name, ItemsInFolder, LastModified*, creationtime

Get Teams Created in the Last 30 Days


$TeamsStats | ? {$_.CreationTime -gt (get-date).AddDays(-30)} | Format-Table Identity, Name, ItemsInFolder, LastModified*, CreationTime


Obviously you can do your other creative checks and tests as well and trigger automatic or manual actions on specific teams now, armed with this information.


Tony Redmond PowerShell for Inspiration
https://www.petri.com/teams-compliance-story

Find Teams Enabled o365 Groups
https://techcommunity.microsoft.com/t5/Microsoft-Teams/Teams-enabled-O365-Groups-report-workaround-in-PowerShell/td-p/141029