Report · 2 tools
Teams with no owner or only one owner
Summary
Finds teams that have lost their owners, usually because people left. Ownerless teams cannot be managed by members and become a governance and migration risk.
Implementation
Choose your tool. Your choice is remembered on other samples.
Connect-MgGraph -Scopes Group.Read.All -NoWelcome
Get-MgGroup -All -Filter "resourceProvisioningOptions/Any(x:x eq 'Team')" -Property Id, DisplayName, Mail |
ForEach-Object {
$owners = Get-MgGroupOwner -GroupId $_.Id -All
[pscustomobject]@{ Team = $_.DisplayName; Mail = $_.Mail; OwnerCount = $owners.Count
Owners = ($owners.AdditionalProperties.userPrincipalName -join ";") }
} | Where-Object OwnerCount -lt 2 | Sort-Object OwnerCount |
Export-Csv .\teams-owners.csv -NoTypeInformation# PnP PowerShell needs your own Entra app registration (see the "Register a PnP PowerShell app" lab)
$clientId = "<client-id>"
Connect-PnPOnline -Url "https://<tenant>-admin.sharepoint.com" -Interactive -ClientId $clientId
Get-PnPTeamsTeam | ForEach-Object {
$owners = Get-PnPTeamsUser -Team $_.GroupId -Role Owner
[pscustomobject]@{ Team = $_.DisplayName; OwnerCount = @($owners).Count; Owners = ($owners.UserPrincipalName -join ";") }
} | Where-Object OwnerCount -lt 2 | Export-Csv .\teams-owners.csv -NoTypeInformationPrerequisites
- Graph scopes Group.Read.All
- Teams Administrator for the PnP version
Output
CSV of teams with owner count and owner names.
Contributors
| Author | Role |
|---|---|
| Priyanshu Upadhyay | Solution Architect, Microsoft 365 and Azure |
InnovaticT