Report the Membership of Teams Private Channels

Find Teams Private Channels and Their Members with PowerShell

Last week, I wrote about using the Get-AssociatedTeam cmdlet to create a membership report for Microsoft Teams. The report lists all teams that each user belongs to, including their direct membership of shared channels. Some folks got in contact to ask if they could use the cmdlet to generate a report about the membership of Teams private channels. The answer is no, probably because to be a member of a private channel, a user must first be a member of the host team. The host team is in the set returned by Get-AssociatedTeam, so the team is reported for the user anyway.

However, there’s usually another way to attack a problem. In this case, we can leverage the Get-TeamAllChannel cmdlet, another of the new cmdlets Microsoft released in V4.6 of the Microsoft Teams PowerShell module.

Finding Private Channels

Because it contained much of the code I needed (never be too proud to reuse code!), I amended the script I wrote to report all the channels for all teams in a tenant as follows:

  • Check each team for private channels.
  • If any private channels exist, run the Get-TeamChannelUser cmdlet for each channel to find its owners and members.
  • Write out the details of the channel members and owners.
  • Report the data.

Here’s the main loop to process the private channels found in teams and capture details of their owners and members:

$ChannelsList = [System.Collections.Generic.List[Object]]::new()
[int]$i = 0
ForEach ($Team in $Teams) {
   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.DisplayName
     ForEach ($Member in $ChannelMembers) {
       $ChannelLine = [PSCustomObject][Ordered]@{ # Write out details of the private channel and its members
          Team                = $Team.DisplayName
          Channel             = $Channel.DisplayName
          Description         = $Channel.Description
          Member              = $Member.Name
          MemberUPN           = $Member.User
          Role                = $Member.Role
          HostTeam            = $Channel.HostTeamId
          Id                  = $Channel.Id }
       $ChannelsList.Add($ChannelLine) } 
  } #End Foreach Member
} # End ForEach Team

Figure 1 shows some data from my tenant in the PowerShell list that stores the private channel data as viewed through the Out-GridView cmdlet.

Details of the membership of Teams shared channels
Figure 1: Details of the membership of Teams shared channels

Teams reports minimal data for owners and members. If you wanted to include extra information about users like department, office, title, you’d need to look the user up in Azure AD to retrieve the information.

Understanding Private Channel Usage

Even better, we can interrogate the list to calculate basic information about private channel usage in the tenant, such as the number of teams with private channels, the teams that have private channels and their owners (Figure 2).

Basic details of Teams private channels
Figure 2: Basic details of Teams private channels

After generating whatever data that you need, you can then create suitable output reports in CSV, HTML, Excel, or PDF formats.

You can download the full script from GitHub.

Private Channels

I’m not sure if Teams private channels have had the impact Microsoft expected when they revealed the new capability at the Ignite 2019 conference. However, I like private channels because I think they are an effective way to share information with a defined set of people, including sharing documents in the dedicated SharePoint Online site that each private channel has. Sure, app support is limited for shared channels, but that’s no reason to avoid using them when discussions need exists to be a little more private than regular team collaboration.

Insight like this doesn’t come easily. You’ve got to know the technology and understand how to look behind the scenes. Benefit from the knowledge and experience of the Office 365 for IT Pros team by subscribing to the best eBook covering Office 365 and the wider Microsoft 365 ecosystem.

One Reply to “Report the Membership of Teams Private Channels”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.