DEV Community

Cover image for Finding Microsoft Teams with No Owner (or Only One) Using PowerShell
Priya Santos
Priya Santos

Posted on AI-assisted

Finding Microsoft Teams with No Owner (or Only One) Using PowerShell

Every Microsoft 365 tenant I audit has at least one team that nobody owns. The person who created it left, or moved roles, and the team carries on with files, chats and guest access but no one who can manage membership or answer the question "should this still exist?"

A team with a single owner is the same problem waiting to happen. If that person is off sick, on holiday or leaves, nobody can add a new starter, remove a departing contractor or archive the team when the project ends.

This post walks through a short PowerShell script that lists every team with its owner count, so you can spot the gaps and fix them in one sitting.

What you need

You need the MicrosoftTeams PowerShell module and an account with the Teams Administrator or Global Administrator role. Install the module once:

Install-Module MicrosoftTeams -Scope CurrentUser
Enter fullscreen mode Exit fullscreen mode

Then connect:

Connect-MicrosoftTeams
Enter fullscreen mode Exit fullscreen mode

You will be prompted to sign in. If your admin account uses multifactor authentication, which it should, the normal sign-in prompt handles that.

The report script

The script loops through every team, counts owners, members and guests, and builds a simple object for each one:

$report = foreach ($team in Get-Team) {
    $users  = Get-TeamUser -GroupId $team.GroupId
    $owners = $users | Where-Object Role -eq 'Owner'

    [PSCustomObject]@{
        Team        = $team.DisplayName
        Visibility  = $team.Visibility
        Archived    = $team.Archived
        OwnerCount  = @($owners).Count
        MemberCount = @($users | Where-Object Role -eq 'Member').Count
        GuestCount  = @($users | Where-Object Role -eq 'Guest').Count
        Owners      = ($owners.User -join '; ')
        GroupId     = $team.GroupId
    }
}
Enter fullscreen mode Exit fullscreen mode

A few details worth explaining:

  • Get-TeamUser returns everyone in the team with a Role of Owner, Member or Guest, so one call per team gives all three counts.
  • Wrapping results in @() makes sure .Count works even when there is only one owner or none at all.
  • GroupId is kept in the output because you will need it to fix anything the report finds.

Reading the results

Sort by owner count so the problems rise to the top:

$report | Sort-Object OwnerCount | Format-Table Team, OwnerCount, MemberCount, GuestCount, Archived -AutoSize
Enter fullscreen mode Exit fullscreen mode

Then save a copy for your records:

$report | Export-Csv -Path .\TeamsOwnerReport.csv -NoTypeInformation
Enter fullscreen mode Exit fullscreen mode

When I run this for a small firm, the output usually falls into three groups:

  1. Teams with zero owners. These need attention first, especially if the guest count is above zero.
  2. Teams with one owner. These are fine today but fragile. Most should have a second owner.
  3. Archived teams. These can often be left alone, but check whether they still need to exist at all.

If you only want the risky ones, filter the report:

$report | Where-Object { $_.OwnerCount -lt 2 -and -not $_.Archived }
Enter fullscreen mode Exit fullscreen mode

Fixing the gaps

Adding an owner takes one line. The user must be in your tenant, and if they are not already a member, this adds them and promotes them in one step:

Add-TeamUser -GroupId "GROUP-ID-FROM-REPORT" -User "NEW-OWNER-UPN" -Role Owner
Enter fullscreen mode Exit fullscreen mode

For teams that are clearly finished, archiving is usually better than deleting. It keeps the content readable while stopping new activity:

Set-TeamArchivedState -GroupId "GROUP-ID-FROM-REPORT" -Archived $true
Enter fullscreen mode Exit fullscreen mode

Before deleting anything, talk to whoever used the team last. Files in a forgotten team are sometimes the only copy of something a client or regulator might ask for later.

Running it on a schedule

The report takes a few minutes in a small tenant, so it is easy to run monthly. I keep the script in a shared admin folder and add the date to the export file name:

$stamp = Get-Date -Format 'yyyy-MM-dd'
$report | Export-Csv -Path ".\TeamsOwnerReport-$stamp.csv" -NoTypeInformation
Enter fullscreen mode Exit fullscreen mode

Comparing two months side by side makes it obvious when a new ownerless team appears, usually straight after someone leaves.

Wrapping up

Ownerless teams are not dramatic, but they are a quiet governance gap: nobody reviews the members, nobody removes guests and nobody decides when the team should end. A short script and a monthly habit of running it close that gap for very little effort.

A simple rule that works well in small businesses: every team has at least two owners, and at least one of them is a manager rather than whoever happened to click "Create team".

Top comments (0)