Entra / Microsoft 365 · Teams
Report teams private channels
Report the set of Teams private channels and their members 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.
s# ReportTeamsPrivateChannels.PS1# Report the set of Teams private channels and their members for a tenant## Uses the MicrosoftTeams PowerShell module and the Microsoft Graph PowerShell SDK$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.AllSelect-MgProfile Beta[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.Id -MembershipType "Private"ForEach ($Channel in $Channels) {Write-Host ("Found private channel {0} in team {1}" -f $Channel.DisplayName, $Team.DisplayName)[array]$ChannelMembers = Get-TeamChannelUser -GroupId $Team.Id -DisplayName $Channel.DisplayNameForEach ($Member in $ChannelMembers) {$ChannelLine = [PSCustomObject][Ordered]@{ # Write out details of the private channel and its membersTeam = $Team.DisplayNameChannel = $Channel.DisplayNameDescription = $Channel.DescriptionMember = $Member.NameMemberUPN = $Member.UserRole = $Member.RoleHostTeam = $Channel.HostTeamIdId = $Channel.Id }$ChannelsList.Add($ChannelLine) }} #End Foreach Member} # End ForEach Team[array]$TeamsWithPrivateChannels = $ChannelsList | Sort-Object HostTeam -Unique | Select-Object -ExpandProperty Team[array]$ChannelOwners = $ChannelsList | Where-Object {$_.Role -eq "Owner"}$PrivateChannels = $ChannelOwners.Channel | Sort-Object -UniqueCLSWrite-Host "Analysis of Teams Private Channels Complete"Write-Host "-------------------------------------------"Write-Host ""Write-Host ""Write-Host "Total Teams processed: " $Teams.CountWrite-Host "Teams with private channels: " $TeamsWithPrivateChannels.countWrite-Host ""Write-Host "Private channels found in the following teams:" ($TeamsWithPrivateChannels -join ", ")Write-Host ""Write-Host "The owners of the private channels are:"Write-Host ""$ChannelOwners | Format-Table Member, Role, Channel -AutoSize$ChannelsList | Out-GridView$ChannelsList | Export-CSV -NoTypeInformation $OutputfileWrite-Host ""Write-Host "Channels list is in $Outputfile"
Attribution
Author
Office365itpros