SOLVED

Add user to multiple teams

%3CLINGO-SUB%20id%3D%22lingo-sub-331116%22%20slang%3D%22en-US%22%3EAdd%20user%20to%20multiple%20teams%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-331116%22%20slang%3D%22en-US%22%3E%3CP%3EHow%20do%20I%20get%20this%20to%20work%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24teams%20%3D%20Get-Team%20%7C%20Select-Object%20-Property%20GroupId%20%3CBR%20%2F%3EForEach%20(%24team%20in%20%24teams)%20%7B%3CBR%20%2F%3EAdd-TeamUser%20-GroupId%20%24team%20-User%20Adam%40bookkeepingissaquah.com%3CBR%20%2F%3E%7D%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F71998i3B9E2A35519B7D5E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Capture.PNG%22%20title%3D%22Capture.PNG%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EError%20I%20get%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-331116%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMicrosoft%20Teams%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-331196%22%20slang%3D%22en-US%22%3ERe%3A%20Add%20user%20to%20multiple%20teams%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-331196%22%20slang%3D%22en-US%22%3EYour%20right%2C%20its%20working.%20Thank%20you%20so%20much!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-331194%22%20slang%3D%22en-US%22%3ERe%3A%20Add%20user%20to%20multiple%20teams%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-331194%22%20slang%3D%22en-US%22%3E%3CP%3ESo%20the%20user%20is%20already%20added%2C%20move%20to%20the%20next%20one.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-331188%22%20slang%3D%22en-US%22%3ERe%3A%20Add%20user%20to%20multiple%20teams%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-331188%22%20slang%3D%22en-US%22%3E%3CP%3EHere%20is%20the%20error%20I%20got%20when%20I%20tried%20that%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F72012i55C0CB1437AFB987%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Capture2.PNG%22%20title%3D%22Capture2.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-331171%22%20slang%3D%22en-US%22%3ERe%3A%20Add%20user%20to%20multiple%20teams%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-331171%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20are%20passing%20an%20incorrect%20value%2C%20GroupId%20needs%20to%20be%20string%2C%20while%20you%20are%20passing%20an%20object.%20Try%20this%20instead%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAdd-TeamUser%20-GroupId%20%24team.GroupId%20-User%20Adam%40bookkeepingissaquah.com%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1415884%22%20slang%3D%22en-US%22%3ERe%3A%20Add%20user%20to%20multiple%20teams%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1415884%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Zach%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20to%20add%20user%20in%20MS%20Teams%20and%20I%20am%20trying%20to%20execute%20this%20code%20in%20Powershell%20and%20Management%20shell%20but%20I%20am%20unable%20to%20execute%20and%20getting%20below%20error.%20Could%20you%20please%20let%20me%20know%20which%20tool%20you%20have%20used%20to%20run%20this%20code%3F%20Your%20response%20will%20be%20very%20helpful%20to%20me.%3C%2FP%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22error.png%22%20style%3D%22width%3A%20677px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F194242i3D23B8E42593DBFF%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22error.png%22%20alt%3D%22error.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThankyou%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
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 Adam@bookkeepingissaquah.com
}

 

Error I getError I get

5 Replies
Highlighted
Best Response confirmed by Zach_N (Occasional Contributor)
Solution

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 Adam@bookkeepingissaquah.com

Highlighted

Here is the error I got when I tried that:

 

Capture2.PNG

Highlighted

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

Highlighted
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.

 

error.png

 

Thankyou