Skip to content

Script to add users to teams or to private team channels in Microsoft Teams using a CSV file

Notifications You must be signed in to change notification settings

waltervanheuven/Add-UsersToTeamsFromCSVFile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 

Repository files navigation

Add-UsersToTeamsFromCSVFile

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

Installation instructions for Windows

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

Installation instructions for macOS

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/"

Check that module and script are installed

Get-Module -ListAvailable
Get-InstalledScript

Show Help

help Add-UsersToTeamsFromCSVFile.ps1

Update script to latest version

Update-Script Add-UsersToTeamsFromCSVFile

CSV file

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.

Usage

# First connect to Microsoft Teams (AzureCloud)
Connect-MicrosoftTeams

# run script
Add-UsersToTeamsFromCSVFile.ps1 students.csv

About

Script to add users to teams or to private team channels in Microsoft Teams using a CSV file

Topics

Resources

Stars

Watchers

Forks