Teams Updates PowerShell Module for Private Channels

Teams PowerShell Module 1.0.18 Supports Private Channels

Microsoft released support for private channels on November 4 (also see this note about managing private channels). Support for PowerShell access to private channels is not yet available in the publicly available version of the Teams PowerShell module. Instead, if you want to work with private channels through PowerShell, you must install the latest version of the Teams module from the PowerShell test gallery. You need to run version 1.0.18 or better to manage private channels (Figure 1).

The right version of the Teams PowerShell module for Private Channel support
Figure 1: The right version of the Teams PowerShell module for Private Channel support

The latest version of the Teams PowerShell module is 2.0.

New and Updated Cmdlets for Private Channels

The following cmdlets are updated to support private channels:

  • New-TeamChannel: New MembershipType and Owner parameters to set a channel to be private and assign an initial owner.
  • Set-TeamChannel: Now able to update the description or display name of a private channel.
  • Get-TeamChannel: Updated with new MembershipType parameter to only return the set of private channels.
  • Remove-TeamChannel: Can remove a private channel. Use with care!

Three new cmdlets are available to manage the membership of private channels:

  • Add-TeamChannelUser: Add a user to a private channel. You can add someone as an owner or member.
  • Get-TeamChannelUser: Lists the members of a private channel.
  • Remove-TeamChannelUser: Deletes a member from a private channel.

Group Identifier

Like everything to do with Teams when working through PowerShell, you need to know the group identifier of the team hosting the private channel to use any of these cmdlets. The object identifier for a team is easily fetched. In this example, we fetch the group identifier for the team with the display name “Corporate Acquisition Planning” and store it in the $GroupId variable.

# Get Group Id for the Corporate Acquisition Planning team
$GroupId = (Get-Team -DisplayName "Corporate Acquisition Planning 2020").GroupId

Adding a New Private Channel

The New-TeamChannel cmdlet creates a new private channel if you specify that the MembershipType parameter is Private. Remember to add an owner selected from the membership of the team.

# Add new private channel to a team
New-TeamChannel -GroupId $GroupId -DisplayName "Project Hydra" -Description "Discussions about the Hydra Project" -MembershipType Private -Owner

After creating a new private channel, you build out its membership by adding a subset of the members of the team with the Add-TeamChannelUser cmdlet. Specify -Role Owner for the members who will be owners of the private channel. You must first add someone as a member before you can add them as an owner. Everyone in the channel can be an owner, if that’s what you want. Again, the private channel is identified with its display name.

# Add members to the private channel
Add-TeamChannelUser -GroupId $GroupId -DisplayName "Legal Discussions" -User
Add-TeamChannelUser -GroupId $GroupId -DisplayName "Legal Discussions" -User -Role Owner

Channel Membership

Use the Get-TeamChannelUser cmdlet to return the membership of a private channel. Note that you identify the private channel using its display name.

# Fetch channel membership
Get-TeamChannelUser -GroupId $GroupId -DisplayName "Legal Discussions"

UserId                               User                               Name           Role
------                               ----                               ----           ----
eff4cd58-1bb8-4899-94de-795f656b4a18   Tony Redmond   owner
d36b323a-32c3-4ca5-a4a5-2f7b4fbef31c      Kim Akers      member
c6133be4-71d4-47c4-b109-e37c0c93f8d3 Oisin Johnston member
cad05ccf-a359-4ac7-89e0-1e33bf37579e     James Ryan     member

Use the Remove-TeamChannelUser cmdlet to remove an owner or member from a private channel:

# Remove member from a private channel
Remove-TeamChannelUser -GroupId $GroupId -DisplayName "Legal Discussions" -User 

Listing Channels

If you run Get-TeamChannel to list the channels in a team, you see all channels without any indication of which are private, and which are public unless you output the MembershipType property:

# List channels for a team
Get-TeamChannel -GroupId $GroupId

Id                                               DisplayName         Description
--                                               -----------         ----------- General             A team to coordinate the work to id... Acquisition Targets Legal Discussions   Legal debate about our acquisition ... Project Hydra       Discussions about the Hydra Project

Get-TeamChannel -GroupId $GroupId | Format-Table DisplayName, MembershipType

DisplayName         MembershipType
-----------         --------------
General                   Standard
Acquisition Targets       Standard
Legal Discussions          Private<

To select a specific type of channel, use the MembershipType parameter to state the kind of channel you want to return:

# List private channels for a team
Get-TeamChannel -GroupId $Groupid -MembershipType Private

Id                                               DisplayName       Description
--                                               -----------       ----------- Legal Discussions Legal debate about our acquisition pl... Project Hydra     Discussions about the Hydra Project

Updating and Removing a Channel

There’s no way to run a command to change a channel type from Private to Standard or vice versa. All you can do with Set-TeamChannel is update the display name or description.

# Update a channel
Set-TeamChannel -GroupId $GroupId -CurrentDisplayName "Project Hydra" -NewDisplayName "Deep and Dark Secrets" -Description "The place where deep and dark secrets are discussed"

The Remove-TeamChannel cmdlet doesn’t give any warning or seek confirmation when it removes a private channel (and the underlying SharePoint site).

# Remove a private channel
Remove-TeamChannel -GroupId $GroupId -DisplayName "Project Hydra"

Need examples of how to use PowerShell to solve real-life administration challenges with Teams? Check out the “Managing Groups and Teams with PowerShell” chapter in the Office 365 for IT Pros eBook. It’s always easier to create a script based on a working example!

4 Replies to “Teams Updates PowerShell Module for Private Channels”

Leave a Reply

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