Library / Microsoft 365

M365-007 · Script

Teams Governance and Lifecycle

Reviews every Microsoft Teams team for owners, guests, channels and recent activity, and can add a backup owner to ownerless teams.

Version 1.0.0Language PowerShellUpdated November 2026

What it does

Saves a dated CSV in the Reports folder with each team's visibility, owner count, member and guest counts, channel counts (standard, private, shared), creation date, and last activity date from the Teams activity report. Flags: No owner, One owner, Inactive (no activity in -InactiveDays), Has guests. Mode AssignOwner adds -FallbackOwner as an owner of every team that has none. Note: if your tenant hides user and team names in reports, last activity dates may be blank. An admin can change this in the Microsoft 365 admin center under Org settings, Reports.

Requirements

Microsoft Graph PowerShell SDK, installed by you from the PowerShell Gallery (not included). Graph application permissions: Group.Read.All, Channel.ReadBasic.All, Reports.Read.All, and GroupMember.ReadWrite.All for AssignOwner mode. Windows PowerShell 5.1 or PowerShell 7.

How to run it

  • Run from: an admin workstation or scheduled task with the Microsoft modules installed and app sign-in configured
  • This is an admin script for your Microsoft 365 tenant, not a per-device endpoint script
  • User interaction: none with app-only sign-in
  • Schedule: run on demand, or weekly for reports

Settings

NameWhat it doesOptionsDefault
ModeReport (default) or AssignOwner.Report, AssignOwnerReport
FallbackOwnerUPN to add as owner of ownerless teams (AssignOwner mode).
InactiveDaysDays without activity before a team is flagged Inactive. Default: 90.90
SkipChannelsSkip channel counts (faster on large tenants).False
TenantIdDirectory (tenant) ID, for unattended app-only sign-in.
ClientIdApplication (client) ID of your app registration.
CertificateThumbprintThumbprint of the certificate uploaded to the app registration.
UseExistingSessionUse a Microsoft Graph session you already opened with Connect-MgGraph.False

Exit codes

  • 0 = Completed, no ownerless or inactive teams left
  • 1 = Ownerless or inactive teams found, or an action failed
  • 2 = Script error (see log)

Testing steps

  1. Run it first with the mode set to Report on one test account or small group. Nothing is changed in that mode.
  2. Read the log and confirm the planned changes are what you expect.
  3. Run your chosen settings on the same test target and confirm the result.
  4. Check the exit code: 0 = OK, 1 = needs attention, 2 = error (see log), 9 = this copy is past its Valid until date.
  5. Roll out to a small group next, then everyone.

Rollback steps

Report mode changes nothing. Remove an added owner in the Teams admin center or the team's settings.

Version and change log

VersionDateChanges
1.0.0November 2026First release.