Create Teams in bulk using Teams PowerShell

Published by Satyajit Paul on

Create Teams in bulk from CSV using TeamsPowerShell

In this article we will look at how multiple teams can be created from data present in an CSV file. We will be using Teams PowerShell to achieve this. 

System Assumptions:

This script will be executed in a Windows machine, with the Teams creation instructions being read from an CSV file. PowerShell ISE will be used to execute the commands and scripts.

Input File:

This is the scenario. The CSV input file contains 15 teams with their details like – Team name, Team description, Visibility and owner of the team. We will use this data as the input for creating our teams via a PowerShell script.

Command for creating a team:

The command for creating a team via PowerShell is shown below.

New-Team -DisplayName "My Dummy Team" -Description "This is a dummy team" -Owner "dev@collablogic.onmicrosoft.com" -Visibility Public

The above cmdlet creates a new team with parameters we specify and returns a Group object with a GroupID property. Along with this, an associated O365 Unified Group is also created to back the team. To get more details about this command, run this below cmdlet to view the detailed help.

Get-Help New-Team 

Script for bulk creation of teams:

The script that will create the teams from input file is as follows – 

#Connnect to Microsoft Teams
$connection = Connect-MicrosoftTeams
try
{
   #CSV File Path. Change this location accordingly
   $filePath = "C:\Users\Satya\Desktop\CreateBulkTeams.csv"

    #read the input file
   $loadFile = Import-Csv -Path $filePath

    foreach ($row in $loadFile)
   {
       $teamName = $row.'Team name'
       $teamDescription = $row.'Team description'
       $teamOwner = $row.Owner
       $teamVisibility = $row.Visibility

        #create the team with specified parameters
       $groupID = New-Team -DisplayName $teamName -Owner $teamOwner -Description $teamDescription -Visibility $teamVisibility
       Write-Host "Team " $teamName " created successfully..."
   }

    Write-Host $loadFile.Count " teams were created" -ForegroundColor Green -BackgroundColor Black
}

catch
{
     Write-Host "An error occurred:"
     Write-Host $_
} 

Illustration:

The code is outlined as –

  • Establish a connection with the Teams tenant
  • Read the CSV file
  • Execute the Teams creation command within a foreach loop

It first establishes a connection via the Connect-MicrosoftTeams cmdlet. Upon successful authentication, it moves to the next stage of reading data from the input csv. After the file load is successful, it then traverses through the foreach loop and creates the team with the specified parameters. The corresponding Office 365 groups providing the backbone to the Teams is also created.

Upon completion of the script, if we login to the Teams, we can see the new teams being added there. 

The corresponding groups can also be seen from Admin Center

(Microsoft 365 Admin Center >> Groups)

This explains a simple scenario of how Teams creation can be planned and provisioned to a large scale and organization wise. Manual tasks can be avoided while achieving some level of governance. The input file can be modified with multiple more parameters and make the Teams creation even more meaningful.

This marks the end of this article. In this article we saw how to create Teams in bulk via a simple powershell script.

The PowerShell script can be found in my GitHub repo 

Care to Share?

Satyajit Paul

SharePoint Developer with 6+ years of experience. Skilled in Add-in Development, BPM, CSOM and Migrations.

1 Comment

Rob · November 24, 2021 at 9:11 PM

Hi Satyajit,
Great Article. Thanks. How would you adapt the script to add multiple owners to the Team?

Leave a Reply