GitHub Icon Image

Bulk add members to Microsoft Teams team from CSV file

Summary

This script will add users in existing Teams contained in your .csv file.

  • CLI for Microsoft 365 with PowerShell
<#
.SYNOPSIS
    Add users to a Microsoft 365 group linked to Teams.
.DESCRIPTION
    This script will add users in existing Teams contained in your .csv file.
.EXAMPLE
    PS C:\> .\add-users-teams.ps1
    This script will add users in existing Microsoft Teams teams from your .csv file
.INPUTS
    Inputs (if any)
.OUTPUTS
    Output (if any)
.NOTES
    Your .csv file must contain headers called UPN, teamName, teamId, and role. If you change those headers then make sure to amend the script.
#>

#Check if connected to M365
$m365Status = m365 status
if ($m365Status -match "Logged Out") {
  m365 login
}
    
#Import csv
$usersCsvFile = Import-Csv -Path "<YOUR_CSVFile_PATH_HERE.csv>"

#Add users to the Team
foreach ($row in $usersCsvFile) {
  Write-Host "Adding $($row.UPN) to the $($row.teamName) Team" -ForegroundColor Magenta
  m365 aad o365group user add --groupId $row.teamId --userName $($row.UPN) --role $($row.role)
}

Check out the CLI for Microsoft 365 to learn more at: https://aka.ms/cli-m365

Source Credit

Sample first appeared on Bulk add members to Microsoft Teams team from CSV file | CLI for Microsoft 365

Contributors

Author(s)
Inspired by Rakesh Pandey
Veronique Lengelle

Disclaimer

THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

Back to top Script Samples
Generated by DocFX with Material UI