Entra / Microsoft 365 · Teams
Report teams channels
Report the set of channels existing in Teams for a tenant.
Connect & set up
Run these once per session. All scopes are read-only unless the script makes changes.
Connect-MgGraph -Scopes Group.Read.All, Directory.Read.All
Run it
The main script. Copy it, or download the .ps1 and run it from your console.
param([string] $TenantId = "$Tenant.Id")$Modules = @( "MicrosoftTeams", "Microsoft.Graph" )# Requires -Modules $Modules$Outputfile = "C:\temp\OutputChannels.csv"$ModulesLoaded = Get-Module | Select NameIf (!($ModulesLoaded -match "MicrosoftTeams")) {Write-Host "Please connect to the Microsoft Teams module and then restart the script"; break}Connect-MgGraph -Scopes Group.Read.All, Directory.Read.All$Tenant = (Get-MgOrganization)$TenantName = $Tenant.DisplayName[array]$Teams = Get-MgGroup -Filter "resourceProvisioningOptions/Any(x:x eq 'Team')" -AllIf (!($Teams)) {Write-Host "Can't find any teams - exiting"; break}$Teams = $Teams | Sort-Object DisplayName$ChannelsList = [System.Collections.Generic.List[Object]]::new()[int]$i = 0ForEach ($Team in $Teams) {$i++Write-Host ("Processing {0} ({1}/{2})" -f $Team.DisplayName, $i, $Teams.Count)[array]$Channels = Get-TeamAllChannel -GroupId $Team.IdForEach ($Channel in $Channels) {If ($Channel.TenantId -eq $TenantId) {$Name = $TenantName }Else {$LookUpId = $Channel.TenantId.toString()$Uri = "https://graph.microsoft.com/beta/tenantRelationships/findTenantInformationByTenantId(tenantId='$LookUpId')"$ExternalTenantData = Invoke-MgGraphRequest -Uri $Uri -Method Get$Name = $ExternalTenantData.DisplayName }$ChannelLine = [PSCustomObject][Ordered]@{ # Write out details of the groupTeam = $Team.DisplayNameChannel = $Channel.DisplayNameDescription = $Channel.DescriptionMembershipType = $Channel.MembershipTypeHostTeam = $Channel.HostTeamIdTenantId = $Channel.TenantIdTenant = $NameId = $Channel.Id }$ChannelsList.Add($ChannelLine) }}[array]$TeamsStandardChannels = $ChannelsList | ? {$_.MembershipType -eq "Standard"}[array]$TeamsPrivateChannels = $ChannelsList | ? {$_.MembershipType -eq "Private"}[array]$TeamsSharedChannels = $ChannelsList | ? {$_.MembershipType -eq "Shared"}[array]$TenantsWithChannels = $ChannelsList | Sort-Object Tenant -Unique | Select-Object -ExpandProperty Tenant$AvgChannels = [math]::round(($ChannelsList.Count/$Teams.Count),2)Write-Host ""Write-Host "Total Teams processed: " $Teams.CountWrite-Host "Total channels: " $ChannelsList.CountWrite-Host "Average channels per team: " $AvgChannelsWrite-Host "Total standard channels: " $TeamsStandardChannels.CountWrite-Host "Total private channels: " $TeamsPrivateChannels.CountWrite-Host "Total shared channels: " $TeamsSharedChannels.CountWrite-Host ""Write-Host "Channels found in the following tenants:" ($TenantsWithChannels -join ", ")Write-Host ""$ChannelsList | Export-CSV -NoTypeInformation $OutputfileWrite-Host "Channels list is in $Outputfile"
Parameters
ParameterDefaultNotes
-TenantId$Tenant.IdMicrosoft Entra tenant ID for app-only Graph authentication.Attribution
Author
Office365itpros