Microsoft 365 governance PowerShell script: What are my inactive teams January 18, 2023 By: Syskit team 3 min read A PowerShell script for Microsoft 365 which finds you inactive teams and list them with export option for easier analysis. If you are trying to find a list of all your inactive teams then this PowerShell script is just what you need. The script’s purpose is to find all the teams that have been inactive for a specific time period – 30 days by default. The script gets all the teams, and for each team, it checks Teams chat activity. If you want to check file activity in a team-related SharePoint site and Outlook conversations as well try our Syskit Point – free trial. This PowerShell script will output the teams that have been inactive for a specific time period (30 days by default). If the time period needs to be changed, you can use the -InactivityPeriod parameter, which accepts the number of days. Example: Get-InactiveTeams.ps1 -InactivityPeriod 120 By default, the script outputs the result only to the screen. There are optional flags available to export the result to CSV -ExportCSV (if set, this will automatically export the result to a CSV file. If you do not set an export path, it will export the file to %temp% folder) Example: Get-InactiveTeams.ps1 -InactivityPeriod 60 -ExportCSV -ExportFilePath Example: Get-InactiveTeams.ps1 -ExportCSV -ExportFilePath “C:Tempreport.csv” PowerShell Script code: # Set script parameters [CmdletBinding()] param ( [int]$InactivityPeriod = 30, [switch]$ExportCSV, [string]$ExportFilePath = "$env:TEMP\$(Get-Date -Format "yyyy_MM_dd")InactiveTeams.csv" ) # Check or install Microsoft Graph Reports module if ($null -eq (Get-Module -ListAvailable Microsoft.Graph.Reports)) { try { Write-Output "Microsoft Graph Reports module not found. Trying to install" [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force | Out-Null Install-Module Microsoft.Graph.Reports -Force | Out-Null Write-Output "Microsoft Graph Reports module installed" } catch { Write-Output "Unable to install Microsoft Graph Reports module. $($Error[0].Exception.Message)" Return } } # Connect to M365 try { Write-Output "Connecting Microsoft Graph" Select-MgProfile -Name "beta" Connect-MgGraph -Scopes Reports.Read.All | Out-Null } catch { Write-Output "Unable to connect to M365. $($Error[0].Exception.Message)" Return } # Get activity report try { Get-MgReportTeamActivityDetail -Period 'ALL' -OutFile "$env:Temp\teamsactivityreport.json" } catch { Write-Output "Unable to get activity report. $($Error[0].Exception.Message)" Return } # Read the report for filtering $AllTeamActivity = (Get-Content -Raw "$env:Temp\teamsactivityreport.json" | ConvertFrom-Json).Value # Check each team and build a report $FinalReport = @() foreach ($SingleTeamActivity in $AllTeamActivity) { if ($SingleTeamActivity.lastActivityDate) { $lastActivityDate = Get-Date -Date $SingleTeamActivity.lastActivityDate if ($lastActivityDate -le $((Get-Date).AddDays(-$InactivityPeriod))) { $TeamActivityObject = [PSCustomObject]@{ TeamId = $SingleTeamActivity.teamId TeamName = $SingleTeamActivity.teamName LastActivityDate = $SingleTeamActivity.lastActivityDate } $FinalReport += $TeamActivityObject } } else { $TeamActivityObject = [PSCustomObject]@{ TeamId = $SingleTeamActivity.teamId TeamName = $SingleTeamActivity.teamName LastActivityDate = "No activity found" } $FinalReport += $TeamActivityObject } } # Print result to the screen Write-Output $FinalReport | Format-Table # Export result to CSV file if needed if ($ExportCSV) { $FinalReport | Export-Csv -Path $ExportFilePath -NoTypeInformation Write-Output "Report saved to $ExportFilePath" } # Stop before closing powershell window Read-Host "Script completed. Press 'Enter' to finish" Get a list of inactive teams quickly with Syskit Point Syskit Point a Microsoft 365 governance and management platform, can get you a list of inactive teams by checking team chat activity, team-related SharePoint site activity, and Outlook conversations. Syskit Point can generate various reports in real time. You can easily access them online and share them with your colleagues or managers with a simple link. Additionally, you can schedule reports, export them in excel or PDF, and perform management actions directly from a report. Easily check Project Server sites, security and database information, operational policies, time and task management settings, the projects list, and project permissions. Discover, secure, and control M365 Manage your company’s Microsoft 365 ecosystem with Syskit Point, a scalable platform that will help you govern and secure your environment while giving you deep visibility into your entire inventory. Try for free Related Posts Microsoft 365 governance How to provision Microsoft Teams using Power Automate Learn how to set up Microsoft Teams provisioning and approval workflows with Po… August 2, 2021 7 min read Microsoft 365 governance Microsoft Teams permissions This blog will tackle questions related to Microsoft Teams governance, such as … December 1, 2022 8 min read Microsoft 365 governance Top 9 Office 365 governance tools Here is our list of the top out-of-the-box tools that can help give you a head … September 24, 2019 7 min read