Microsoft Teams provides a secure and collaborative workspace for organizations, but tracking private Teams across a tenant can be challenging. Private Teams restrict access to only invited members, making it essential for IT administrators to monitor their existence, membership, and status. This article presents a Graph PowerShell script that retrieves all private Microsoft Teams in a tenant and displays:
Below is the PowerShell script that retrieves all private Teams and their details.
# Install & Import Graph Module (if not already installed)
Install-Module Microsoft.Graph -Scope CurrentUser
Import-Module Microsoft.Graph
# Connect to Microsoft Graph
Connect-MgGraph -Scopes "Group.Read.All", "Team.ReadBasic.All"
# Fetch all Teams (no direct filter for 'visibility', so we filter later)
$AllTeams = Get-MgGroup -Filter "resourceProvisioningOptions/any(x:x eq 'Team')" -Property Id, DisplayName, Description, Visibility -All
# Filter out only Private Teams
$PrivateTeams = $AllTeams | Where-Object { $_.Visibility -eq "Private" }
if ($PrivateTeams.Count -eq 0) {
Write-Host "No private Microsoft Teams found in the tenant." -ForegroundColor Yellow
} else {
$TeamDetails = @()
foreach ($Team in $PrivateTeams) {
# Fetch Team Members
$Members = Get-MgGroupMember -GroupId $Team.Id -All
$MemberCount = ($Members | Measure-Object).Count
# Fetch Team Owners
$Owners = Get-MgGroupOwner -GroupId $Team.Id -All
$OwnerCount = ($Owners | Measure-Object).Count
# Fetch Team Archive Status
$TeamData = Get-MgTeam -TeamId $Team.Id -Property IsArchived
$ArchiveStatus = if ($TeamData.IsArchived -eq $true) { "Archived" } else { "Active" }
# Store details in custom object
$TeamDetails += [PSCustomObject]@{
"Team Name" = $Team.DisplayName
"Team Description" = $Team.Description
"Member Count" = $MemberCount
"Owner Count" = $OwnerCount
"Archive Status" = $ArchiveStatus
}
}
# Display Results in Table Format
$TeamDetails | Format-Table -AutoSize
}
# Disconnect from Graph
Disconnect-MgGraph
Here are some improvements that can be made to the script:
$TeamDetails | Export-Csv -Path "PrivateTeamsReport.csv" -NoTypeInformation
| Error | Cause | Solution |
| Error: No private Microsoft Teams found in the tenant | No private teams exist in the tenant. | Verify that private teams exist before running the script. |
| Get-MgGroupMember: Access Denied | The account lacks permissions. | Ensure Group.Read.All and Team.ReadBasic.All are granted and admin consented. |
| Visibility filter error | The visibility property cannot be filtered directly in Graph API. | The script correctly filters teams after retrieving all Teams. |
| Get-MgTeam: Not Found | The team may not be fully provisioned or accessible. | Ensure the team exists and is accessible via Microsoft Graph. |
visibility eq 'Private' to Retrieve Private TeamsGet-MgGroup cmdlet filters Microsoft 365 groups (including Teams) based on visibility.
To fetch only private Teams, use the following filter:-Filter "resourceProvisioningOptions/Any(x:x eq 'Team') and visibility eq 'Private'"
"Team" and "Private" attributes helps list all private Teams — whether created directly in Teams or via apps like Planner or SharePoint.
This PowerShell script provides an efficient and automated way to retrieve private Microsoft Teams from a Microsoft 365 tenant. It allows administrators to monitor team members, owners, and archive status, ensuring better governance and compliance. With additional enhancements like CSV exports and scheduled execution, this script can become a powerful tool in Microsoft Teams administration.
© m365corner.com. All Rights Reserved. Design by HTML Codex