🔧 New: User Management Graph PowerShell Toolkit

Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.

🚀 Launch Toolkit

Fetch All Microsoft Teams Owners Using Graph PowerShell

Managing ownership across Microsoft Teams is critical for governance, lifecycle management, and compliance. This script helps administrators list all Teams owners along with their sign-in status using Graph PowerShell.


The Script

# Connect to Microsoft Graph with required scopes
Connect-MgGraph -Scopes "Group.Read.All", "User.Read.All"
                                
# Initialize variables
$headers = @{
    "ConsistencyLevel" = "eventual"
}
$teamsOwners = @()
$uri = "https://graph.microsoft.com/v1.0/groups?`$filter=resourceProvisioningOptions/Any(x:x eq 'Team')&`$select=id,displayName&`$top=50"
                                
# Paginate through all Teams
do {
    $response = Invoke-MgGraphRequest -Method GET -Uri $uri -Headers $headers
    $teams = $response.value
                                    
    foreach ($team in $teams) {
    $teamId = $team.id
    $teamName = $team.displayName
                                    
    # Fetch owners of each team
    $ownersUri = "https://graph.microsoft.com/v1.0/groups/$teamId/owners?`$select=displayName,userPrincipalName,accountEnabled"
    $ownersResponse = Invoke-MgGraphRequest -Method GET -Uri $ownersUri
                                    
    foreach ($owner in $ownersResponse.value) {
        $teamsOwners += [PSCustomObject]@{
            "Team Name"      = $teamName
            "Owner Name"     = $owner.displayName
            "Owner Mail"     = $owner.userPrincipalName
            "Sign In Status" = if ($owner.accountEnabled -eq $true) { "Allowed" } else { "Denied" }
        }
    }
    }
                                    
    $uri = $response.'@odata.nextLink'
} while ($uri)                  
    # Output results
    if ($teamsOwners.Count -eq 0) {
    Write-Host "No Microsoft Teams owners found." -ForegroundColor Yellow
    } else {
    $teamsOwners | Format-Table -AutoSize
}
                            

How the Script Works

  1. Authentication: The script begins with Connect-MgGraph using the required scopes.
  2. Team Discovery: It queries all groups with a resourceProvisioningOptions value of "Team" to identify Microsoft Teams.
  3. Owner Retrieval: For each team, it fetches the owners using a /groups/{id}/owners call.
  4. Data Structuring: Each owner’s name, UPN, and sign-in status are stored in a PowerShell object.
  5. Output Display: Displays the data in a neatly formatted table using Format-Table.

Further Enhancements

Here are some ways to extend this script:

  • Filter by inactive owners: Add logic to identify owners who are disabled or haven’t logged in recently.
  • Export to CSV: Pipe the results to Export-Csv for offline review.
  • Include Team creation date or description: Add additional fields by modifying the /groups query.
  • Visual dashboard: Feed this data into Power BI or a simple HTML table for reporting.

Use Cases

This script is extremely useful for:

  • ✅ Auditing Teams Ownership: Ensuring every Team has at least one active owner.
  • 🔐 Security Reviews: Identifying owners whose accounts are disabled.
  • 🧹 Cleanup Activities: Detecting orphaned Teams with no active owners.
  • 📋 Compliance Reporting: Generating up-to-date ownership records for audits.

Possible Errors & Solutions

Error Cause Solution
Access Denied Missing permissions Ensure Group.Read.All and User.Read.All Graph API scopes are granted
Invoke-MgGraphRequest returns null Pagination not handled properly Always check for @odata.nextLink to fetch all records
Sign In Status missing Some owners may be external guests Include userType and accountEnabled check for better clarity

Conclusion

This script provides a clean, efficient, and extensible way to fetch all Microsoft Teams owners using Graph PowerShell. Whether you're handling governance, auditing, or automation—this is a must-have tool in your IT admin toolkit.

💡 Tip: For better automation, schedule this script to run weekly and store results in a centralized location for tracking changes in ownership.


Graph PowerShell Explorer Widget

20 Graph PowerShell cmdlets with easily accessible "working" examples.


Permission Required

Example:


                


                


                

© m365corner.com. All Rights Reserved. Design by HTML Codex