How to add bulk users from CSV file to MS Teams using PowerShell
Hi everyone !! Today we will see How to add bulk users from CSV file to MS Teams using PowerShell. We will use PowerShell script to add the users. I know there must be other ways also to do this but as I am big fan of PowerShell scripting. Hence I have done it using scripting.
Connecting MS teams via PowerShell
- Install Microsoft teams module for MS Teams.
- Launch powershell with admin rights.
- Run Install-Module -Name MicrosoftTeams
- Refer this link for package information
- Type “A” to install all the features.
In my previous blog I have described How to install and connect with Power Platform ? This also a bit similar to this, you can refer earlier blog for an idea.
Connect to MS Teams
Run command “Connect-MicrosoftTeams” and enter the credentials.

Once you provide the credentials, you will able to see below screen.

Prepare your CSV file
After connecting to MS team, now we will prepare our csv file. Refer below screen shot to make a csv file. Save the csv file as Adduser. You can save this file whatever name you like.

PowerShell Script to create Team and User.

##This script will be used to create a Team and add bulk user from csv file to the newly created team.
##Before running this script use Connect-MicrosoftTeams to connect your MS Teams.
##Version 1.0 Date 24-2-2020
##Created By Rakesh Pandey
$date = Get-Date -Format M
$logfile = "E:\Powershell_Output_Script\$date-useraddlog.txt"
$startdt = [System.DateTime]::Now
Write-Output "Start Time: $startdtr
n" | Out-File $logfile -Append
Write-Output "**" | Out-File $logfile -Append
$inputcsvfile = Import-Csv (Read-Host "Enter CSV Location")
$teamName = Read-Host "Please enter Team Name"
$teamDescription = Read-Host "Please enter Team Description"
##Create Team
New-Team -DisplayName $teamName -Description $teamDescription
$grp = Get-Team -DisplayName $teamName
$grpid = $grp.GroupId
Write-Output "Created Team: $teamName groupid: " $grpid | Out-File $logfile -Append
##Add user from csv file
foreach($line in $inputcsvfile)
{
Add-TeamUser -GroupId $grpid -User $line.EmailAddres -Role $line.Role -ErrorAction SilentlyContinue
Write-Output "Added user: "$line.EmailAddres" Role: "$line.Role | Out-File $logfile -Append
}
Write-Output "**" | Out-File $logfile -Append
$enddt = [System.DateTime]::Now
Write-Output "End Time: $enddtr
n" | Out-File $logfile -Append
This script requires below information from user.
1) CSV file name and location
2) Team Name
3) Team Description
After providing these details you will able to see the new team under teams and user already added into it.

Please share and subscribe this article in case you like it. Drop us an email to [email protected] for an MS teams related issues or training.
Thanks for the Tutorial!
This would be even better if there is a way to define the SMTP email address when the Teams is created. Because as currently, a randomly generated email is assigned to the group.
Hi John,
Thanks for visiting our site and suggestion. We can provide a user friendly Mail Nick name using -MailNickName parameter.
The MailNickName parameter specifies the alias for the associated Office 365 Group. This value will be used for the mail enabled object and will be used as PrimarySmtpAddress for this Office 365 Group. The value of the MailNickName parameter has to be unique across your tenant.
So the updated code will be like below.
##Create Team
New-Team -DisplayName $teamName -Description $teamDescription -MailNickname “userfriendlynamewithoutspace” .
Please try at your end and let us know whether its working or not.
Thanks.
hello sir
can you guide in how to add bulk members a channel (private) created within a team
Hi Vinny,
You can use Add-TeamChannelUser -GroupId 31f1ff6c-d48c-4f8a-b2e1-abca7fd399df -DisplayName “Engineering” -User [email protected] -Role Owner command. You can use the csv file the way I have used. If unable to form the script, please let me know.
Hi Rakesh,
How do we add this so it creates the team with privates channels and adds members to each private channel?
I added a column on .csv as TeamType and put Private or Public but cant get the scripts work. It is ignoring and creating public channels. Thank you so much
Hi Fatima, -DisplayName “” -MembershipType Private
Use the below code.
New-TeamChannel -GroupId
My script needs a little bit of modification to cater to your need. Hence you need to create a team firstly then channel using the above code. You can use a CSV file. Please let me know if you need any help in building the script.
Thank you Rakesh. I do need help with the script as I am not sure where I should add this. I assume all needs to be a member first then grouped into individual private channels?
Much appreciated.
$date = Get-Date -Format M
$logfile = “log file location\$date-useraddlog.txt”
$startdt = [System.DateTime]::Now
Write-Output “Start Time: $startdt rn” | Out-File $logfile -Append
Write-Output “**” | Out-File $logfile -Append
$inputcsvfile = Import-Csv (Read-Host “Enter CSV Location”)
$teamName = Read-Host “Please enter Team Name”
$teamDescription = Read-Host “Please enter Team Description”
$privateChannelName = Read-Host “Please enter private channel name”
##Create Team
New-Team -DisplayName $teamName -Description $teamDescription
$grp = Get-Team -DisplayName $teamName
$grpid = $grp.GroupId
Write-Output “Created Team: $teamName groupid: ” $grpid | Out-File $logfile -Append
## Create New Channel private
New-TeamChannel -GroupId $grpid -DisplayName $privateChannelName -MembershipType Private
##Add user from csv file
foreach($line in $inputcsvfile)
{
Add-TeamUser -GroupId $grpid -User $line.EmailAddres -Role $line.Role -ErrorAction SilentlyContinue
Add-TeamChannelUser -GroupId $grpid -DisplayName $privateChannelName -User $line.EmailAddres -Role $line.Role
Write-Output “Added user: “$line.EmailAddres” Role: “$line.Role | Out-File $logfile -Append
}
Write-Output “**” | Out-File $logfile -Append
$enddt = [System.DateTime]::Now
Write-Output “End Time: $enddt rn” | Out-File $logfile -Append
Use the same CSV. Update the log file location in the script.
Hi Rakesh
Great tutorial, any pointers on how it could be modified, to create the teams from a CSV and populate each teams membership
Hi Justin,
Thanks for glancing the tutorial. In order to create a new team you can use New-Team command. See the below example from MS site. You can incorporate this in a CSV file. Follow this link for more details : https://docs.microsoft.com/en-us/powershell/module/teams/New-Team?view=teams-ps
$group = New-Team -MailNickname “TestTeam” -displayname “Test Teams” -Visibility “private”
Add-TeamUser -GroupId $group.GroupId -User “[email protected]”
Add-TeamUser -GroupId $group.GroupId -User “[email protected]”
Add-TeamUser -GroupId $group.GroupId -User “[email protected]”
New-TeamChannel -GroupId $group.GroupId -DisplayName “Q4 planning”
New-TeamChannel -GroupId $group.GroupId -DisplayName “Exec status”
New-TeamChannel -GroupId $group.GroupId -DisplayName “Contracts”
Also let us know if you need any helping hand to build the script.
Hello Rakesh ,
Thanks for this full article of managing teams by scripts in powershell.
By the way , do you have a template for creating random groups from CSV file and adding also the members from another CSV file ?
If you have any idea , or the template , thanks in advance for the share.
Regards ,
Marwan
Hi Rakesh
Good article,
Could you also share the powershell script to add Guest users like gmail users to Teams
Hi Sam,
Currently, Microsoft Teams cmdlet doesn’t provide any command to add guest users.
You can check this post, it may help you.
HI Rakesh,
Thanks for the above script but i need your help here with little customization as i am not sure if above mentioned script (your response to Fatima) can add multiple channels with the members and their roles..
I need to –
1. create a team / private / with team users (all info from CSV)
2. create channels / private / each channel has different members with their roles as owner/member (all info from CSV)
appreciate your help here.
Lemme create a script based on your requirement and will post soon.
Thanks J
Script needs to account for $teamName with spaces
Hi Rakesh,
How to create bulk private and standard channels in teams via PowerShell? Could you please give me script for the same ?
Appreciate your help!
Regards,
Vinod
Hi Vinod,
You can use the -MembershipType parameter of New-TeamChannel to create private and standard channels. Do you want the whole script? Please let us know.
Thanks.
I keep getting an error: “Add-TeamUser : Cannot bind argument to parameter “GroupID’ because it is null.”