1. Home
  2. Knowledge Base
  3. Microsoft
  4. Microsoft Teams
  5. Adding users in bulk to Microsoft Teams using PowerShell

Adding users in bulk to Microsoft Teams using PowerShell

How to add multiple users in bulk to Microsoft Teams?

Microsoft Teams offers a great way to communicate with colleagues and collaborators. You can easily manually add users one at a time to your team from the Teams app, but what if you need to add a large number of users? Microsoft Teams doesn’t allow you to add members in bulk when creating a new team.

The good news is that we can use PowerShell for this! Adding bulk users to your Microsoft Teams account can be a time-consuming process, especially when you have a lot of new employees to add. This article shows you how to add bulk users in Microsoft Teams. Adding or removing members/owners to Microsoft Teams can be done using PowerShell, as per my other post: Managing Microsoft Teams with PowerShell; this post is about adding users in bulk.

I’m assuming you already have the Microsoft Teams PowerShell module installed on your computer. If not, install it: How to install PowerShell module for Microsoft Teams?

Adding users to Microsoft Teams is a four-step process:

  1. Connection to Microsoft Teams with PowerShell
  2. Find the GroupID of the team you want to add users to.
  3. Populate a CSV file with a list of all users to add to the team
  4. Use a PowerShell script to read the CSV file and add members to the team.

Step 1: Connect to Microsoft Teams via PowerShell

First, we need to connect to Microsoft Teams via PowerShell. Use the Connect-MicrosoftTeams cmdlet to establish the connection.

1 Connect-MicrosoftTeams

You will be prompted to log in. Enter your Microsoft Teams credentials to connect to Teams via PowerShell. This popup is MFA enabled, i.e. H. even if your account has multi-factor authentication enabled, you can sign in to PowerShell and connect to Microsoft Teams. Make sure you have ownership rights for the team you want to add the users to.

Step 2: Find out the Microsoft Teams Group ID

The next step is to find out the GroupID associated with each team.

When a team is created in Microsoft Teams, an associated Microsoft 365 group is also created in the backend. This acts as the backbone for the teams. So, to manage the team, we need to get the ID of the associated group. Let’s get the GroupID from the team display name:

1 #Get Team ID from Display Name

2 Get-Team | Where {$_.DisplayName -eq "Learning Portal"} | Select -ExpandProperty GroupID

If you’re not sure about the teams’ display name, just use the Get-Team cmdlet to get all the teams in your environment.

1 #Get All Teams

2 Get-Team

Step 3: Fill a CSV file with users to add to the team

Here is my CSV file. Just provide the email addresses of the users and the role you want to assign as a member or owner in the CSV file.

Add users to teams in bulk

Here I used the user’s email and the role to be assigned in the CSV file. You can also use TeamName as a parameter.

Step 3: Fill a CSV file with users to add to the team

Finally, here is the complete PowerShell script to add multiple users to an existing Microsoft Teams team from a CSV file!

1 #Get users from the CSV

2 $TeamUsers = Import-Csv -Path "C:\Temp\TeamsUsers.csv"

3

4 #Iterate through each user from the CSV and add to Teams

5 $TeamUsers | ForEach-Object {

6 Add-TeamUser -GroupId $TeamID -User $_.Email -Role $_.Role

7 Write-host "Added User:"$_.Email -f Green

8 }

PowerShell script to add users to Microsoft Teams in bulk

Let’s introduce parameters and add some error handling to the pieces above. Here is the full script to add users in bulk to Microsoft Teams from a CSV file:

1 #Parameters

2 $CSVPath = "C:\Temp\TeamsUsersTemplate.csv"

3 $TeamDisplayName = "Learning Portal"

4

5 Try {

6 #Connect to Microsoft Teams

7 Connect-MicrosoftTeams

8

9 #Get Team ID from Display Name

10 $TeamID = Get-Team | Where {$_.DisplayName -eq $TeamDisplayName} | Select -ExpandProperty GroupID

11 #Get users from the CSV

12

13 $TeamUsers = Import-Csv -Path $CSVPath

14 #Iterate through each user from the CSV and add to Teams

15

16 $TeamUsers | ForEach-Object {

17 Try {

18 Add-TeamUser -GroupId $TeamID -User $_.Email -Role $_.Role

19 Write-host "Added User:"$_.Email -f Green

20 }

21 Catch {

22 Write-host -f Red "Error Adding User to the Team:" $_.Exception.Message

23 }

24 }

25 }

26 Catch {

27 write-host -f Red "Error:" $_.Exception.Message

28 }

You can also use this script to add guest users to Microsoft Teams in bulk!

Dieser Beitrag ist auch verfügbar auf: Deutsch (German)

Was this article helpful?

Related Articles

Submit a Comment

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

Skip to content