December 4, 2020

KNOWLITE

Never stop learning.

Bulk Creating Microsoft Teams

2 min read

As Microsoft has recently released the PowerShell module for Microsoft Teams, we can finally manage (almost all) features of a Team with PowerShell!

Official page:
https://github.com/MicrosoftDocs/office-docs-powershell/tree/master/teams/teams-ps/teams

Installing the PowerShel Module

Install-MicrosoftTeams

Connecting to Teams

Connect-MicrosoftTeams

Creating a Team

$Group = New-Team -DisplayName "Your Team name here" -Description "Your Description here" -MailNickName "YourMailNickName here" -Visibility "Private/Public" -Owner "Enter your owner here"

Adding members to your freshly created Team

As you see, we have captured the created group above by making it a variable.
We need the GroupId to add or change anything on an existing group.

Below we use the captured GroupId to add a member.

Add-TeamUser -GroupId $Group.GroupId -User "UserName here" -Role "Member/Owner"

Creating a channel in this Team

New-TeamChannel -GroupId $Group.GroupId -DisplayName "Enter your displayname here"

Time to get bulky!

Using the above cmdlets we can combine all thos magical PowerShells to create multiple teams with members and channels based on 1 input file

For the team I have used the following parameters:
DisplayName
MailNickname
Visibility
Owner

Both members and channel names are separated with a colon (;)

Note: I have used some parameters to create a Team, feel free to use more parameters by adding them to the input file and adding them in the script.
All available settings can be viewed on the followin GitHub Page:
https://docs.microsoft.com/en-us/powershell/module/teams/new-team?view=teams-ps

#This script was made to bulk create Teams
Connect-MicrosoftTeams
$TeamsList = Import-CSV .\Teams.csv
Foreach ($Team in $TeamsList) {

#Testing if a Team with the same name already exists
If ((Get-Team -DisplayName $Team.DisplayName) -eq $Null){

#Creating The teams and setting the Owner of the Team
$Group = New-Team -DisplayName $Team.DisplayName -MailNickname $Team.MailNickname -Visibility $Team.Visibility -Owner $Team.Owner

#Adding Default Channels for the Team
$Channels = $Team.Channels.Split(";")
Foreach($Channel in $Channels){
New-TeamChannel -GroupId $Group.GroupId -DisplayName $Channel
}

#Adding Team members for each Team as member
$Members = $Team.Members.Split(";")
Foreach($Member in $Members) {
Add-TeamUser -GroupId $Group.GroupId -User $Member -Role Member
}
Write-Host ("Success: The Team with name " + $Team.DisplayName + " was created")
}
Else {Write-Host ("Error: The Team with name: " + $Team.DisplayName + " already exists")}
}

More Stories

4 min read