Add user to multiple teams

Occasional Contributor

How do I get this to work?


$teams = Get-Team | Select-Object -Property GroupId 
ForEach ($team in $teams) {
Add-TeamUser -GroupId $team -User


Error I getError I get

6 Replies
best response confirmed by Zach_N (Occasional Contributor)

You are passing an incorrect value, GroupId needs to be string, while you are passing an object. Try this instead:


Add-TeamUser -GroupId $team.GroupId -User

Here is the error I got when I tried that:



So the user is already added, move to the next one.

Your right, its working. Thank you so much!

Hi Zach,


I want to add user in MS Teams and I am trying to execute this code in Powershell and Management shell but I am unable to execute and getting below error. Could you please let me know which tool you have used to run this code? Your response will be very helpful to me.








Hi so I ran the following to do what you where looking at. 


$teams = Import-CSV 'D:\Scripts\msteams.csv'

Add-TeamUser -GroupId $_.GroupId -user <emailaddress> -Role Owner}