Create Private channel in Microsoft Teams using PowerShell

Creating private channels on Microsoft Teams is possible by default in all organizations. In this blog, we will explore how to create a new private channel in a team and add members using PowerShell.

Before you start, install the latest Microsoft Teams PowerShell module and run the following command to connect the Teams module.

Connect-MicrosoftTeams

Create a new Private channel in an existing Team

We can use the New-TeamChannel cmdlet to create a new private channel. We need to pass the following parameters to this command to create a new channel.

  • GroupId – Group id of the team to which we are going to add the new channel.
  • MembershipType – Specify this parameter value as Private to create a private channel. A Standard channel will be created if you run the command without this parameter. 
  • Owner – Provide UPN of the user who is already available in the existing team’s membership.

We can use the Get-Team cmdlet to find the existing team’s GroupId with the team’s display name. 

$GroupId = (Get-Team -DisplayName "Test Team 01").GroupId

The following command creates the new private channel in the existing team and adds the given team member as an owner of the channel.

New-TeamChannel -GroupId $GroupId -DisplayName "Private Channel 01" -Description "This is a private channel" -MembershipType Private -Owner "[email protected]"

Add members to Private Channel

Once you successfully created a private channel, we can use the Add-TeamChannelUser cmdlet to add any user as a member or owner of the channel. The following command adds the required user as a member of the private channel.

Add-TeamChannelUser -GroupId $GroupId -DisplayName "Private Channel 01" -User "[email protected]"

Add owner to the channel

To add a user as an owner to the channel, we must first add the user as a member and then promote the user as an owner.

#Add the user AllanD as a member
Add-TeamChannelUser -GroupId $GroupId -DisplayName "Private Channel 01" -User "[email protected]"
#Promote the user AllanD as an owner
Add-TeamChannelUser -GroupId $GroupId -DisplayName "Private Channel 01" -User "[email protected]" -Role Owner

If a member of the team is not added as a member of the private channel, then the user will not be able to view the private channel in the Teams client. Team owners can see the private channel but cannot access it if they are not a member. You can refer to this post to know the difference between Standard and Private Channels.

You will get the following error if you try to add a user as a member of the private channel who is not in the team’s membership.

Add-TeamChannelUser : Error occurred while executing Add-TeamChannel. User Code: NotFound. Message: User is not found in the team.

Advertisement