Skip to content

Instantly share code, notes, and snippets.

@patrick138
Last active April 25, 2021 00:26
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save patrick138/83ba1745cf162e5e75437ab844fb6783 to your computer and use it in GitHub Desktop.
Save patrick138/83ba1745cf162e5e75437ab844fb6783 to your computer and use it in GitHub Desktop.
Add users from text file or csv to a Microsoft Teams site
Adding multiple users to teams by PowerShell and a text / CSV file
1) Create a .txt file like this
Name
name.name@domain.com
name2.name2@domain.com
2) Install the Teams PowerShell tools:
Install-Module -Name MicrosoftTeams
-RequiredVersion 0.9.0
3) Find the GroupId
PS get-team
4) Run this script
Import-Csv 'd:\email.txt' | % {
Add-TeamUser -User $_.Name -GroupId <GroupID>
}
It takes about 30 minutes or more before you see the updates users in Teams. Also an error will be displayed for all users that are alreay present.
$path='d:\email.txt'
$GroupId=<groupid>
Import-Csv $path | % {
Add-TeamUser -User $_.Name -GroupId $GroupId
}
@PeterWxin
Copy link

Thank you! I will give it a try.
$_.Name
Does that part have to be exactly the same as your script?

@patrick138
Copy link
Author

Hi,

You can change it to anything you like as long as your txt file starts with the same.
In case of $.Name the txt will be :
Name
name.name@domain.com
name2.name2@domain.com

or in case of $.blah
blah
name.name@domain.com
name2.name2@domain.com

@djasti7
Copy link

djasti7 commented Aug 15, 2019

Hi Patrick,
I tried your script, but I have an error at $_.Name.
According to my template, I have my user's name format as firstname.lastname@domain.com
I am getting an error at that name field. Can you please help me.

@patrick138
Copy link
Author

patrick138 commented Aug 16, 2019 via email

@djasti7
Copy link

djasti7 commented Aug 16, 2019

These are the user email in my email.txt file

Sudheer.Paygude@domain.com
Adithi.Portier@domain.com
advik.grover@domain.com
abhijit.das@domain.com
suma.kawade@domain.com

This is my script. In group i will add my team group id

$path='C:\Users\suma\Downloads\package\email.txt'
$GroupId=

Import-Csv $path | % {
Add-TeamUser -User $_.Name -GroupId $GroupId
}

@patrick138
Copy link
Author

patrick138 commented Aug 16, 2019 via email

@alextabuscaro
Copy link

Hi.
Thanks for the solution - it works great, though it has one limitation that was not mentioned here :).
It works ONLY WITH MEMBERS - I cannot add guests to my team. Do you know of any possibility to bulk add (by importing a CSV for example) guest users to a team? (users with email addresses outside of the tenant). I can do this manually from the Teams interface but it takes forever if you have to do it with tens of users for multiple teams :(.

@MMMcMahon
Copy link

Hey Patrick - this is awesome. For extra credit, do you know how to:

  1. tag users as they are added; and
  2. Prevent MS Teams from sending an email?

Answers to either or both of those would greatly improve my happiness. :)

@PeterWxin
Copy link

Hi.
Thanks for the solution - it works great, though it has one limitation that was not mentioned here :).
It works ONLY WITH MEMBERS - I cannot add guests to my team. Do you know of any possibility to bulk add (by importing a CSV for example) guest users to a team? (users with email addresses outside of the tenant). I can do this manually from the Teams interface but it takes forever if you have to do it with tens of users for multiple teams :(.

Here's another post I found which might be a solution if you edit the role column in CSV file:
https://flexmind.co/blog/how-to-add-bulk-users-from-csv-file-to-ms-teams-using-powershell/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment