PowerShell script to add users to teams or to private team channels in Microsoft Teams using a CSV file. Users are added using their email address.
You can install the script by downloading the script from this github page or by installing it directly from the PowerShell Gallery:
https://www.powershellgallery.com/packages/Add-UsersToTeamsFromCSVFile
Download and install PowerShell from github.com/PowerShell/PowerShell
Start PowerShell from the Start Menu and install MicrosoftTeams module
Install-Module -Name MicrosoftTeams -RequiredVersion 1.1.10-preview -AllowPrerelease
Install Add-UsersToTeamsFromCSVFile script
Install-Script -Name Add-UsersToTeamsFromCSVFile
Install PowerShell using brew in the Terminal App.
brew install powershell
Start PowerShell in Terminal
pwsh
Install MicrosoftTeams and Script
Install-Module -Name MicrosoftTeams -RequiredVersion 1.1.10-preview -AllowPrerelease
Install-Script -Name Add-UsersToTeamsFromCSVFile
Get location of PowerShell gallery scripts.
Get-InstalledScript -Name "Add-UsersToTeamsFromCSVFile" | Format-List InstalledLocation
Due to PowerShell bug on macOS you need to add the installed script location /Users/[YOUR_USERNAME]/.local/share/powershell/Scripts/
to the path so that the PowerShell can find the installed scripts.
$env:PATH += ":/Users/[YOUR_USERNAME]/.local/share/powershell/Scripts/"
Get-Module -ListAvailable
Get-InstalledScript
help Add-UsersToTeamsFromCSVFile.ps1
Update-Script Add-UsersToTeamsFromCSVFile
The script requires a CSV file. This file should contain a header with the names of the columns. To add users to a team, the CSV file needs to have the columns 'email' and 'team'.
email,team
[email protected],Module1 Team
[email protected],Module1 Team
[email protected],Module2 Team
[email protected],Module2 Team
To add users to a private channel in a team, the CSV file needs to have the columns 'email', 'team', and 'privatechannel'. If a user is not a member of the team they will be added to the team first and then to the private channel within the team.
email,team,privatechannel
[email protected],Seminar Group,Channel1
[email protected],Seminar Group,Channel1
[email protected],Seminar Group,Channel2
[email protected],Seminar Group,Channel2
Please note that if the team or private channel name contains a comma or quotes your need to use quotes around the name. For example, the team name Seminar's team, 1
should have quotes around the name in the csv file: "Seminar's team, 1"
. If you use Excel to create a CSV file and save the file as CSV, Excel will automatically add the quotes.
# First connect to Microsoft Teams (AzureCloud)
Connect-MicrosoftTeams
# run script
Add-UsersToTeamsFromCSVFile.ps1 students.csv