Bulk Add Users to Microsoft Teams using PowerShell
Requirement: Bulk add users to Microsoft Teams from a CSV file.
How to Add Multiple Users to Microsoft Teams in Bulk?
Microsoft Teams offers a great way to communicate with colleagues and collaborators. You can easily add users to your team manually, one at a time, through the Teams app, but what if you need to add a large number of users? Microsoft Teams does not allow you to bulk add members when you are creating a new team.
The good news is we can utilize PowerShell to do that! Adding bulk users to your Microsoft Teams account can be a time-consuming process, especially if you have a lot of new employees to add. This article will show you how to add bulk users in Microsoft Teams. Adding or removing Members/Owners to Microsoft Teams can be done with PowerShell, as in my other post: Managing Microsoft Teams using PowerShell; this post aims at adding users in bulk.
I assume you have the Microsoft Teams PowerShell module is already installed on your computer. If not, install it: How to Install PowerShell module for Microsoft Teams?
There are four steps involved in adding users to Microsoft Teams:
- Connect to Microsoft Teams using PowerShell
- Obtain the GroupID of the Team you wish to add users.
- Populate a CSV file with the list of all users to add to the Team
- Use PowerShell script to read the CSV file and add members to the Team.
Step 1: Connect to Microsoft Teams using PowerShell
To start with, We have to connect to Microsoft Teams from PowerShell. Use the Connect-MicrosoftTeams cmdlet to establish the connection.
Connect-MicrosoftTeams
You’ll be prompted to login. Enter your Microsoft Teams credentials to connect with Teams from PowerShell. This popup is MFA aware, so even if your account has multi-factor authentication enabled, you’d be able to log in to PowerShell and connect to Microsoft Teams. Make sure you have the owner rights for the team you want to add the users to.
Step 2: Get the Group ID of the Microsoft Team
The next step is to obtain the GroupID associated with the particular Team.
When a team is created in Microsoft Teams, at the backend, an associated Microsoft 365 group is also created. This acts as a backbone for the Teams. So, in order to manage the team, we need to obtain the ID of the associated group. Let’s get the GroupID from the display name of the Team:
#Get Team ID from Display Name
Get-Team | Where {$_.DisplayName -eq "Learning Portal"} | Select -ExpandProperty GroupID
If you are unsure about the display name of the Teams, Just use the Get-Team cmdlet to get all teams in your environment.
#Get All Teams
Get-Team
Step 3: Populate a CSV file with Users to Add to the Team
Here is my CSV file. Just specify the Emails of the users and the role to assign members or owners in the CSV.
Here, I have used the Email of the user and Role to assign in the CSV file. You can also use TeamName as a parameter.
Step 4: Import Users from CSV to Microsoft Teams using PowerShell
Finally, Here is the complete PowerShell script to add multiple users to an existing Microsoft Teams Team from a CSV file!
#Get users from the CSV
$TeamUsers = Import-Csv -Path "C:\Temp\TeamsUsers.csv"
#Iterate through each user from the CSV and add to Teams
$TeamUsers | ForEach-Object {
Add-TeamUser -GroupId $TeamID -User $_.Email -Role $_.Role
Write-host "Added User:"$_.Email -f Green
}
PowerShell Script to Bulk Add Users to Microsoft Teams
Let’s introduce parameters and add some error handling to the above chunks. Here is the complete script to Bulk Add Users to Microsoft Teams from a CSV:
#Parameters
$CSVPath = "C:\Temp\TeamsUsersTemplate.csv"
$TeamDisplayName = "Learning Portal"
Try {
#Connect to Microsoft Teams
Connect-MicrosoftTeams
#Get Team ID from Display Name
$TeamID = Get-Team | Where {$_.DisplayName -eq $TeamDisplayName} | Select -ExpandProperty GroupID
#Get users from the CSV
$TeamUsers = Import-Csv -Path $CSVPath
#Iterate through each user from the CSV and add to Teams
$TeamUsers | ForEach-Object {
Try {
Add-TeamUser -GroupId $TeamID -User $_.Email -Role $_.Role
Write-host "Added User:"$_.Email -f Green
}
Catch {
Write-host -f Red "Error Adding User to the Team:" $_.Exception.Message
}
}
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
You can also use this script to bulk-add guest users to Microsoft Teams!
Hi,
How can we use this to bulk add guest users? Doesn’t seem to work as you suggested.
Can you please update this KB
I am having the same problem with guest users
Thank you so much. I updated group from csv files, working great.
Please i am stuck in this line:
Add-TeamUser -GroupId $TeamID -User $_.Email -Role $_.Role
Write-host “Added User:”$_.Email -f Green.
How do i input the commands, my group ID is 9d6a3377-9bb5-4acf-91e7-8feb2cb242a2, is it the same thing as the Team ID? What’s about the User $_.Email-Role $_.Role
Use: Get-Team -GroupId “Group-ID” to get the team. Yes, The group id of a team is the same with the associated Microsoft 365 group.