Automating your Microsoft Teams creation process using PowerShell

Ivan (이반) Porta
2 min readJan 21, 2021

--

Microsoft Teams’ daily users are skyrocketing. From April 2020 to October 2020, their numbers rose more than 50 percent from 75 million to 115 million.

Suppose your company decides to adopt this software for daily internal or external communications. In that case, you might face the manual construction of public/private teams and channels, assign Office 365 users to them, and so on. This procedure might become very time consuming as the complexity of your company increases.

To solve this problem, I have created a script that takes care of all of this for you by automating the entire process. The only thing you must do is create a JSON file as described below and pass a few parameters to the script.

Configuration file

This JSON file contains all the teams and channels that you want to create in your organization. You can also specify each object’s visibility (private or swtandard), the users you wish to assign to it, and their roles.
The schema of the JSON is the following:

The following example shows how to create different teams and channels with multiple users and permissions:

Script

This script is based on the official Microsoft Teams PowerShell module.
If you are using a version of PowerShell prior the 1.0.18, you might face the following error:

New-TeamChannel : A parameter cannot be found that matches parameter name 'MembershipType'.At line:1 char:101
+ ... upId -DisplayName PrivateChannelDisplayName -MembershipType Private
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-TeamChannel], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.TeamsCmdlets.PowerShell.Custom.NewTeamChannel

The problem is that the creation of private channels is not supported by versions prior to 1.0.18. At the time of this writing, I am using the version 1.1.10-preview.

The logic of this script is straightforward. However, there are few keynotes:

  1. Because each team and private channel has its dedicated SharePoint communication site, channels are created asynchronously. To solve possible issues related to assigning users to an incomplete instance, the function Add-UserToPrivateChannel will perform several attempts to set users to a private channel.
  2. If you want to set a user as the owner of a private channel, the user must first be added as a standard user and then changed to the owner.

References

--

--

Ivan (이반) Porta

Microsoft Certified DevOps Engineer Expert | MCT | MCE | Public Speaker