Entra / Microsoft 365 · Teams
Report teams tags
Report teams that have tags defined to tag members.
Connect & set up
Run these once per session. All scopes are read-only unless the script makes changes.
Connect-MgGraph -NoWelcome -TenantId $TenantId -AppId $AppId -CertificateThumbprint $Thumbprint# Necessary scopes: Directory.Read.All, TeamworkTag.Read.All, Channel.ReadBasic.All, Team.ReadBasic.All
Run it
The main script. Copy it, or download the .ps1 and run it from your console.
param([string] $TenantId = "Your tenant identifier",[string] $AppId = "")# Identifier for the app holding the necessary permissions# Thumbprint for an X.509 certificate uploaded to the app$Thumbprint = "F79286DB88C21491110109A0222348FACF694CBD"Connect-MgGraph -NoWelcome -TenantId $TenantId -AppId $AppId -CertificateThumbprint $Thumbprint# Necessary scopes: Directory.Read.All, TeamworkTag.Read.All, Channel.ReadBasic.All, Team.ReadBasic.AllWrite-Host "Finding Teams..."[array]$Teams = Get-MgTeam -All | Sort-Object DisplayName$Report = [System.Collections.Generic.List[Object]]::new()ForEach ($Team in $Teams) {Write-Host "Processing team" $Team.DisplayName[array]$TeamTags = Get-MgTeamTag -TeamId $Team.Id -ErrorAction SilentlyContinueIf ($TeamTags) { # The team has some tagsForEach ($Tag in $TeamTags) {$TagMembers = (Get-MgTeamTagMember -TeamId $Team.Id -TeamWorkTagId $Tag.Id) | Select-Object -ExpandProperty DisplayName$ReportLine = [PSCustomObject][Ordered]@{Team = $Team.DisplayNameTeamId = $Team.IdTag = $Tag.DisplayNameDescription = $Tag.DescriptionMembers = $TagMembers -Join ", "TagId = $Tag.Id }$Report.Add($ReportLine)} #End Foreach Tag} #End If TeamTags} #End ForEach team[array]$TeamsWithTags = $Report.TeamId | Sort-Object -Unique[array]$UniqueTags = $Report.TagId | Sort-Object -UniqueWrite-Host "Total teams: " $Teams.CountWrite-Host "Teams with tags: " $TeamsWithTags.CountWrite-Host "Total tags: " $UniqueTags.Count$Report | Select-Object Team, Tag, Description, Members | Out-GridView
Parameters
ParameterDefaultNotes
-TenantIdYour tenant identifierMicrosoft Entra tenant ID for app-only Graph authentication.-AppId""Application (client) ID for the app registration used to connect.Attribution
Author
Office365itpros