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.
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
| Name | What it does | Options | Default |
|---|---|---|---|
| Mode | Report (default) or AssignOwner. | Report, AssignOwner | Report |
| FallbackOwner | UPN to add as owner of ownerless teams (AssignOwner mode). | ||
| InactiveDays | Days without activity before a team is flagged Inactive. Default: 90. | 90 | |
| SkipChannels | Skip channel counts (faster on large tenants). | False | |
| TenantId | Directory (tenant) ID, for unattended app-only sign-in. | ||
| ClientId | Application (client) ID of your app registration. | ||
| CertificateThumbprint | Thumbprint of the certificate uploaded to the app registration. | ||
| UseExistingSession | Use 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
- Run it first with the mode set to Report on one test account or small group. Nothing is changed in that mode.
- Read the log and confirm the planned changes are what you expect.
- Run your chosen settings on the same test target and confirm the result.
- Check the exit code: 0 = OK, 1 = needs attention, 2 = error (see log), 9 = this copy is past its Valid until date.
- 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
| Version | Date | Changes |
|---|---|---|
| 1.0.0 | November 2026 | First release. |