Hi everyone !! Today we will see How to add bulk users from CSV file to MS Teams using PowerShell. We will use PowerShell script to add the users. I know there must be other ways also to do this but as I am big fan of PowerShell scripting. Hence I have done it using scripting.
In my previous blog I have described How to install and connect with Power Platform ? This also a bit similar to this, you can refer earlier blog for an idea.
Run command “Connect-MicrosoftTeams” and enter the credentials.
Once you provide the credentials, you will able to see below screen.
After connecting to MS team, now we will prepare our csv file. Refer below screen shot to make a csv file. Save the csv file as Adduser. You can save this file whatever name you like.
##This script will be used to create a Team and add bulk user from csv file to the newly created team.
##Before running this script use Connect-MicrosoftTeams to connect your MS Teams.
##Version 1.0 Date 24-2-2020
##Created By Rakesh Pandey
$date = Get-Date -Format M
$logfile = "E:\Powershell_Output_Script\$date-useraddlog.txt"
$startdt = [System.DateTime]::Now
Write-Output "Start Time: $startdtr
n" | Out-File $logfile -Append
Write-Output "**" | Out-File $logfile -Append
$inputcsvfile = Import-Csv (Read-Host "Enter CSV Location")
$teamName = Read-Host "Please enter Team Name"
$teamDescription = Read-Host "Please enter Team Description"
##Create Team
New-Team -DisplayName $teamName -Description $teamDescription
$grp = Get-Team -DisplayName $teamName
$grpid = $grp.GroupId
Write-Output "Created Team: $teamName groupid: " $grpid | Out-File $logfile -Append
##Add user from csv file
foreach($line in $inputcsvfile)
{
Add-TeamUser -GroupId $grpid -User $line.EmailAddres -Role $line.Role -ErrorAction SilentlyContinue
Write-Output "Added user: "$line.EmailAddres" Role: "$line.Role | Out-File $logfile -Append
}
Write-Output "**" | Out-File $logfile -Append
$enddt = [System.DateTime]::Now
Write-Output "End Time: $enddtr
n" | Out-File $logfile -Append
This script requires below information from user.
1) CSV file name and location
2) Team Name
3) Team Description
After providing these details you will able to see the new team under teams and user already added into it.
Please share and subscribe this article in case you like it. Drop us an email to [email protected] for an MS teams related issues or training.