Get All Inactive Microsoft Teams with PowerShell – A Quick Guide

Microsoft Teams has rapidly evolved into a powerhouse collaboration tool for organizations across the globe. But with great usage comes great clutter. Over time, unused or inactive Teams start to pile up — consuming resources, cluttering your environment, and potentially posing compliance or governance risks. That’s where PowerShell scripting comes in handy — especially for identifying and managing inactive Teams.

In this blog, we’ll explore how to get all inactive Teams using PowerShell, what this means, why it matters, who it’s useful for, best practices to follow, and how it stacks up against other approaches.


🧠 What It Means to Get “Inactive Teams”

An inactive Team is typically a Microsoft 365 Group with a connected Team that hasn’t had any user activity (like chat messages, file uploads, or meetings) over a certain period — usually 30, 60, or 90+ days. This lack of activity often indicates that the Team is no longer in use, was created for a temporary project, or simply forgotten.

Using PowerShell, we can query these Teams and their associated activity through the Microsoft Graph API or by leveraging the Teams PowerShell module, often in combination with audit logs or reports generated by the Microsoft 365 Activity API.


💡 Why You Need It

Leaving inactive Teams unchecked can lead to:

  • Governance issues – Difficult to manage ownership and permissions.
  • Licensing waste – Consuming licenses and storage unnecessarily.
  • Security risks – Dormant Teams might still have sensitive information or shared external access.
  • End-user confusion – Overcrowded navigation and irrelevant content make user experience suffer.

By proactively identifying and managing these Teams, you ensure a clean, secure, and optimized Teams environment, enabling better lifecycle governance and compliance alignment.


👤 Who Uses It?

This script is essential for:

  • Microsoft 365 Admins / Global Admins
  • Security and Compliance Officers
  • IT Governance Managers
  • Managed Service Providers (MSPs)
  • Automation Engineers working on Microsoft 365

If you’re maintaining a medium-to-large Microsoft 365 tenant, you’ll find this approach invaluable in automating your digital workplace hygiene.


🔧 What Applications Use It?

To run the PowerShell script for inactive Teams, you typically use:

  • Microsoft Teams PowerShell Module (MicrosoftTeams)
  • Exchange Online PowerShell Module (for mailbox activity)
  • Microsoft Graph API (advanced usage)
  • Audit Log Reports (via Security & Compliance Center or Graph)

✅ Best Practices Before You Start
  • Always connect with the least privilege necessary.
  • Enable audit logging in Microsoft 365 if it isn’t already — inactivity is often measured using audit logs.
  • Tag Teams with metadata (e.g., project, department, creation date) to help with cleanup decisions.
  • Don’t delete immediately — always communicate with owners and apply a grace period.
  • Log results and actions taken for transparency and compliance.

🧾 Sample PowerShell Code to Get Inactive Teams

Here’s a basic script that checks Teams activity using the Microsoft Graph API and PowerShell:

# Connect to Microsoft Teams
Connect-MicrosoftTeams

# Install Microsoft Graph PowerShell SDK if not installed
Install-Module Microsoft.Graph -Scope CurrentUser

# Connect to Graph
Connect-MgGraph -Scopes "AuditLog.Read.All", "Group.Read.All"

# Set your inactivity threshold (in days)
$inactiveThreshold = 90
$cutoffDate = (Get-Date).AddDays(-$inactiveThreshold)

# Get all Teams
$teams = Get-Team

# Empty array for results
$inactiveTeams = @()

foreach ($team in $teams) {
    $groupId = $team.GroupId

    # Check audit log activity (sample logic)
    $activity = Search-UnifiedAuditLog -StartDate $cutoffDate -EndDate (Get-Date) -Operations "SendMessage", "FileAccessed" -UserIds "*" -RecordType ExchangeAdmin | 
        Where-Object { $_.AuditData.TeamId -eq $groupId }

    if (-not $activity) {
        $inactiveTeams += [PSCustomObject]@{
            DisplayName = $team.DisplayName
            GroupId     = $team.GroupId
            CreatedDate = $team.CreatedDateTime
        }
    }
}

# Export results
$inactiveTeams | Export-Csv "InactiveTeams.csv" -NoTypeInformation

Note: The Microsoft Graph API provides a more robust approach for real-world implementations. You’ll need application permissions and an app registration in Azure AD if you’re using app-based auth.


📌 Use Cases & Sample Implementations
  1. Quarterly Governance Review
    Run this script quarterly to find stale Teams and notify owners to review for archival or deletion.
  2. Onboarding Automation
    Integrate into your Microsoft 365 lifecycle policies — inactive Teams older than 90 days get automatically tagged or moved for archival.
  3. Reporting for Leadership
    Export data for department heads to take action on unused Teams — this promotes shared responsibility.

🔁 Alternative Approaches – How Does PowerShell Compare?
ApproachFlexibilityAccuracyEase of UseAutomation Ready
PowerShell (Manual)✅ High✅ High⚠️ Medium✅ Yes
Microsoft Teams Admin Center Reports⚠️ Limited⚠️ Medium✅ Easy❌ No
Microsoft Graph API (Direct Call)✅ High✅ High⚠️ Complex✅ Yes
Third-Party Tools (e.g., ShareGate, Quest)✅ High✅ High✅ Easy✅ Yes

PowerShell hits the sweet spot between control and cost. While admin reports are user-friendly, they lack deep filtering and automation capabilities. Microsoft Graph API offers precision but comes with a steeper learning curve. Third-party tools are polished but often paid.


📉 Pros and Cons
Pros:
  • 💡 Full control over logic and filters
  • 🔁 Automation-friendly
  • 🔍 Can be scheduled or integrated into broader workflows
  • 💰 Free if you already have admin access
Cons:
  • 🧱 Steep learning curve for beginners
  • 🔒 Requires correct permissions and scopes
  • ⚠️ Depends on audit log availability (retention limited to 90/180 days unless E5)

Keeping your Microsoft Teams environment clean and secure is not just good practice — it’s essential in today’s compliance-heavy world. PowerShell provides a powerful, flexible, and cost-effective way to monitor and manage inactive Teams before they become a problem.

Whether you’re a seasoned Microsoft 365 admin or just starting, knowing how to identify inactive Teams and take appropriate action ensures you’re in control of your digital workplace.


🔗 Useful Resources

Authentication Automation Backup Compliance Content Type CSS Flows Google GULP Javascript Levels Limitations Metadata MFA Microsoft Node NodeJs O365 OneDrive Permissions Persmissions PnP PnPJS Policy Power Automate PowerAutomate PowerShell React ReactJs Regex Rest API Rest Endpoint Send an HTTP Request to SharePoint SharePoint SharePoint List SharePoint Modern SharePoint Online SPFX SPO Starter Kit Sync Tags Teams Termstore Versioning

Leave a Comment

Your email address will not be published. Required fields are marked *