PowershellTeams

How To Create Teams & Channels Using CSV And Powershell

Here is another Tutorial I will show you how to Create Teams & Channels using CSV and Powershell. Often office365 Admins will receive the list to create hundreds of teams and channels for school, collages, or for small companies. Making all those Teams and Channels by hand will take ages to complete the task, but with the power of Powershell scripting, we can do this in minutes

Install Microsoft Teams Powershell Module

First, we need to install the Microsoft Teams module for Powershell by running the following command.

Install-Module -Name MicrosoftTeams
Install-Microsoft-Teams-Powershell-Module

Once the installation of the module is complete, its always good practice to check what commands are available to us for the module we just installed by running the following command.

Get-Command -Module MicrosoftTeams
Get-Command -Module MicrosoftTeams

Creating CSV File For Importing Data

Now we are almost ready to start scripting the bulk creation of Microsoft Teams and Channels. The last thing we need is data in the CSV file. I have created the CSV file with the necessary fields, and you can copy the same data for you as well. If you make to make some adjustments to CSV fields, you can do that because I will explain the code to you so you can customize your CSV file and Powershell script for creating bulk Teams and Channels.

Here is my CSV File with Fields necessary to create Teams and Channels and temp data. You need to enter the actual data you received from your management.

csv-file-for-Team-creation

Importing CSV File Data

Now everything is ready, so let’s start building our script. First, we need to import data from our saved CSV file to our Powershell variable called $data by running the following command. Remember, you need to put your CSV path because your CSV path might be different than mine.

$data = Import-Csv C:\Scripts\bulkTeams.csv

Creating and Running The Script

Once the data is in the variable, we need to loop through data to create the Teams and Channels by running the following command.

If you don’t have much knowledge about Powershell below code might be hard fro you to digest but don’t worry its very easy. I will explain you few things which might help ou to understand the code.

foreach ($d in $data) {
    $GroupID = (New-Team -DisplayName $d.TeamDisplayName -Description  $d.TeamDescription`
-MailNickName $d.MailNickName -Visibility $d.TeamVisibility -Owner $d.Owner).GroupID

New-TeamChannel -GroupId $GroupID -DisplayName $d.ChannelDisplayName -Description $d.ChannelDescription

}

Basically, in the above code block, Foreach Loop is used, which reads every object in the array of objects. We are using Foreach Loop to read for us each line, and then we are using that data to create out Teams and channels.

That’s all it’s so simple, and with the few lines of code, we can finish the works in a few seconds, which might take days without Powershell scripting.

Final Script

Here is the complete code you will need to Bulk Create the Microsoft Teams and Channels.

$data = Import-Csv C:\Scripts\bulkTeams.csv
foreach ($d in $data) {
    $GroupID = (New-Team -DisplayName $d.TeamDisplayName -Description  $d.TeamDescription`
-MailNickName $d.MailNickName -Visibility $d.TeamVisibility -Owner $d.Owner).GroupID

New-TeamChannel -GroupId $GroupID -DisplayName $d.ChannelDisplayName -Description $d.ChannelDescription

}

Result

Teams-Created
Channel-Info

Muhammad Faizan

Hi, My name is Muhammad Faizan and i have spent last 15 years working as System Administrator mainly with Microsoft Technologies. I am MCSE, MCTP, MCITP, certified professional. I love scripting and Powershell is the scripting language i am in love with.

Related Articles

5 Comments

  1. it would also be good to mention about -Template options too for those in an educational environment where they will need the EDU_Class option to be applied.

  2. This is amazing and so simple, i’m happy with not adding users as we get our teachers to do this, great work !

    i really must learn powershell.

    1. Ok, i will add that as well in the script. I have done this already for my personal use so it’s just going to take copy/paste. If you need any other help related to Powershell feel free to fill the Contact Us form and i always reply those who contact me. Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also
Close
Back to top button