In Microsoft Teams management, understanding which teams have the most owners can be crucial for ensuring proper governance and oversight. Teams with multiple owners might be easier to manage but could also lead to challenges in coordination and decision-making. This article provides a PowerShell script that lists the top Microsoft Teams in your tenant based on the owner count, with the team having the highest number of owners appearing at the top. This information can help administrators identify teams that may require closer management or review.
# Ensure the Microsoft Graph PowerShell module is installed
# Install-Module Microsoft.Graph -Scope CurrentUser -Force
# Connect to Microsoft Graph
Connect-MgGraph -Scopes "Group.Read.All"
# Get all Microsoft Teams
$teams = Get-MgGroup -Filter "resourceProvisioningOptions/Any(x:x eq 'Team')" -All -Property Id, DisplayName
# Initialize an array to store team and owner count
$teamOwnerCounts = @()
# Loop through each team and get the owner count
foreach ($team in $teams) {
$owners = Get-MgGroupOwner -GroupId $team.Id -All
$teamOwnerCounts += [PSCustomObject]@{
"Team Name" = $team.DisplayName
"Owner Count" = $owners.Count
}
}
# Sort the teams by Owner Count in descending order
$sortedTeams = $teamOwnerCounts | Sort-Object "Owner Count" -Descending
# Output the sorted teams with their owner counts
$sortedTeams | Format-Table -AutoSize
# Disconnect from Microsoft Graph
Disconnect-MgGraph
This script efficiently retrieves and sorts Microsoft Teams based on the number of owners each team has. Below is a step-by-step explanation of how the script operates:
The provided script serves as a solid base for listing teams by owner count. However, you can enhance it further to meet specific needs:
Error: Insufficient privileges to complete the operation.
Cause: The user account does not have the required permissions to read group information.
Solution: Ensure the account has the Group.Read.All permission in Microsoft Graph. You may need to ask an administrator to grant this permission.
Error: Rate limit exceeded.
Cause: The script makes too many requests to the Microsoft Graph API in a short period.
Solution: Introduce a delay between requests or implement retry logic in the script to handle rate limits gracefully.
Error: The owner count returns as zero.
Cause: The Get-MgGroupOwner cmdlet might not be returning results due to connectivity issues or because the group genuinely has no owners.
Solution: Ensure that the teams in question have owners and that the script is running without connectivity issues. If the problem persists, try re-running the script or manually verifying the team owner count through the Teams admin center.
This PowerShell script provides an effective way to list and sort Microsoft Teams by the number of owners, giving you insight into team ownership within your organization. By identifying teams with unusually high or low owner counts, you can ensure that governance policies are being followed and make informed decisions about team management.
The script is also a starting point for further customization, allowing you to tailor it to your specific needs. Whether you need to focus on particular teams, export the results, or automate the process, this script can be extended to fit those requirements.
If you found this script helpful, consider incorporating it into your regular team management processes or further enhance it to provide more detailed insights into your Microsoft Teams environment.
© m365corner.com. All Rights Reserved. Design by HTML Codex