SOLVED
Home

Powershell script to add members to teams?

%3CLINGO-SUB%20id%3D%22lingo-sub-54241%22%20slang%3D%22en-US%22%3EPowershell%20script%20to%20add%20members%20to%20teams%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-54241%22%20slang%3D%22en-US%22%3E%3CP%3EIs%20there%20a%20powershell%20script%20to%20add%20exiting%20AD%20users%2Fmembers%20to%20Exisitng%20Teams%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-54241%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-214207%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20to%20add%20members%20to%20teams%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-214207%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20works%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgist.github.com%2Fpatrick138%2F83ba1745cf162e5e75437ab844fb6783%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgist.github.com%2Fpatrick138%2F83ba1745cf162e5e75437ab844fb6783%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-193873%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20to%20add%20members%20to%20teams%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-193873%22%20slang%3D%22en-US%22%3EHave%20you%20ever%20tried%20the%20below%20example%20before%3F%20When%20i%20do%2C%20the%20owner%20that%20is%20added%20is%20not%20able%20to%20add%20apps%20to%20the%20new%20Team%2C%20where%20as%20anyone%20else%20added%20as%20a%20owner%20%2F%20member%20from%20the%20front%20end%20is%20able%20to%3CBR%20%2F%3E%3CBR%20%2F%3EScenario%20%3A%3CBR%20%2F%3E%3CBR%20%2F%3ECreate%20a%20New%20Team%20Via%20Powershell%20(Service%20Account)%3CBR%20%2F%3EAdd%20another%20Owner%3CBR%20%2F%3EGo%20to%20front%20interface%20and%20install%20apps...%20result%20fails%20to%20install%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-193869%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20to%20add%20members%20to%20teams%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-193869%22%20slang%3D%22en-US%22%3E%3CP%3EYes%20%3A%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EConnect-MicrosoftTeam%3C%2FP%3E%3CP%3EAdd-TeamUser%20-GroupId%20%24(%24TheTeam.GroupId)%20-Role%20Owner%2FMember%20-User%20%24UserPrincipalName%3C%2FP%3E%3CP%3EDisconnect-MicrosoftTeams%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-167648%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20to%20add%20members%20to%20teams%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-167648%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20an%20open%20Premier%20case%20about%20this%20capability.%20%26nbsp%3B%20The%20case%20notes%20say%20that%20our%20issue%20appears%20to%20be%20%22enableDynamicMembershipTeams%20value%20is%20set%20to%20False%20for%20tenant%22.%26nbsp%3B%20This%20gives%20me%20hope%20that%20this%20capability%20will%20be%20available%20soon.%20%26nbsp%3B%20It%20would%20still%20require%20a%20AD%20PRemeium%20license%20though.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-135584%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20to%20add%20members%20to%20teams%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-135584%22%20slang%3D%22en-US%22%3EThanks%20very%20much%20Dean%20for%20the%20link%2C%20I've%20read%20that%20article%20before%20but%20appears%20to%20have%20some%20new%20information%20in%20there.%20Actually%20turns%20out%20it's%20just%20P1%20to%20support%20dynamic%20groups%20as%20well%20which%20is%20a%20plus%2C%20(which%20luckily%20I%20have)%20but%20now%20working%20out%20the%20dynamics%20of%20using%20powershell%20with%20custom%20functions%2C%20it's%20not%20standard%20cmdlets%20to%20enable%20this%20in%20powershell.%20%3CBR%20%2F%3E%3CBR%20%2F%3ECheers!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-135566%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20to%20add%20members%20to%20teams%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-135566%22%20slang%3D%22en-US%22%3E%3CP%3ETeams%20members%20are%20stored%20in%20Azure%20AD%20groups%2C%20those%20can%20be%20populated%20dynamically%20if%20you%20have%20Azure%20AD%20P2%20licenses%2C%20see%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory%2Factive-directory-groups-dynamic-membership-azure-portal%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory%2Factive-directory-groups-dynamic-membership-azure-portal%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-135565%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20to%20add%20members%20to%20teams%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-135565%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F8023%22%20target%3D%22_blank%22%3E%40Sonia%20Cuff%3C%2FA%3E%26nbsp%3Bis%20there%20any%20news%20about%20MS%20Teams%20supporting%20dynamic%20(attribute-based)%20memberships%20now%2C%20or%20soon%20in%20the%20future%3F%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-135564%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20to%20add%20members%20to%20teams%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-135564%22%20slang%3D%22en-US%22%3E%3CP%3Eis%20there%20a%20difference%20between%20this%20Unified%20Group%20and%20the%20Azure%20AD%20powershell%20Add-AzureADGroupMember%20cmdlet%2C%20for%20example%3F%20I%20just%20did%20some%20tests%20with%20the%20AAD%20powershell%20and%20that%20managed%20to%20work%20for%20editing%20membership%20of%20a%20MS%20Team%20(supported%20by%20its%20underlying%20O365%20group).%20I%20was%20just%20curious%20what%20capabilities%20or%20what%20is%20different%20with%20this%20UnifiedGroup%20cmdlet%20I%20see%20mentioned%20here%20and%20on%20some%20MS%20blogs.%26nbsp%3B%20%26nbsp%3BThanks!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-56016%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20to%20add%20members%20to%20teams%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-56016%22%20slang%3D%22en-US%22%3E%3CP%3EDynamic%20group%20creation%20has%20been%20delayed%20and%20rolled%20out%20to%20a%20select%20set%20of%20customers%20first%20to%20gather%20more%20feedback.%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FOffice-365-Groups%2FUpdate-Auto-creation-of-Direct-Reports-group-in-Outlook-MC96611%2Fm-p%2F55318%3Futm_content%3Dbufferc6fa2%26amp%3Butm_medium%3Dsocial%26amp%3Butm_source%3Dtwitter.com%26amp%3Butm_campaign%3Dbuffer%23M2740%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FOffice-365-Groups%2FUpdate-Auto-creation-of-Direct-Reports-group-in-Outlook-MC96611%2Fm-p%2F55318%3Futm_content%3Dbufferc6fa2%26amp%3Butm_medium%3Dsocial%26amp%3Butm_source%3Dtwitter.com%26amp%3Butm_campaign%3Dbuffer%23M2740%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-55915%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20to%20add%20members%20to%20teams%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-55915%22%20slang%3D%22en-US%22%3E%3CP%3EYes%2C%20all%20roles%20are%20different%20%22link%22%20types%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAdd-UnifiedGroupLinks%20-Identity%20team%20-LinkType%20Owner%20-Links%20user%40domain.com%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-55500%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20to%20add%20members%20to%20teams%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-55500%22%20slang%3D%22en-US%22%3E%3CP%3EI%20dont%20believe%20I%20have%20the%20option%20of%20using%20the%20Microsoft%20Graph%20API%20yet.%20We%20dont%20have%20any%20Azure%20accounts%20as%20well%20as%20i'm%20not%20quite%20sure%20how%20to%20do%20any%20of%20that.%20I%20still%20just%20connect%20to%20Office365%20through%20a%20Azure%20Active%20Directory%20Module%20for%20Powershell%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20the%20cmdlet%20-%20That%20did%20work.%20Is%20there%20anyway%20to%20also%20set%20the%20role%20as%20well%20for%20the%20user%3F%20(Owner%2FMember)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-55010%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20to%20add%20members%20to%20teams%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-55010%22%20slang%3D%22en-US%22%3E%3CP%3EFYI%2C%20MS%20just%20announced%20that%20some%20groups%20for%20certain%20Managers%20and%20their%20Direct%20Reports%20will%20be%20getting%20created%20automatically%20to%2C%20see%20%3CA%20href%3D%22https%3A%2F%2Fsupport.office.com%2Fen-us%2Farticle%2FManage-automatic-creation-of-direct-reports-group-Admin-help-8387f129-19cc-4426-9911-e36fa0a01043%3Fui%3Den-US%26amp%3Brs%3Den-US%26amp%3Bad%3DUS%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fsupport.office.com%2Fen-us%2Farticle%2FManage-automatic-creation-of-direct-reports-group-Admin-help-8387f129-19cc-4426-9911-e36fa0a01043%3Fui%3Den-US%26amp%3Brs%3Den-US%26amp%3Bad%3DUS%3C%2FA%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETHis%20may%20be%20helpful%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-54992%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20to%20add%20members%20to%20teams%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-54992%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20should%20be%20able%20to%20do%20it%20via%20regular%20cmdlets%20too%2C%20i.e.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAdd-UnifiedGroupLinks%20-Identity%20team%20-LinkType%20Member%20-Links%20user%40domain.com%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%20things%20happen%20slooooooow%20with%20this%20approach%2C%20so%20Graph%20should%20be%20better%20I%20guess.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-54270%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20to%20add%20members%20to%20teams%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-54270%22%20slang%3D%22en-US%22%3EMy%20understanding%20is%20that%20you%20will%20have%20to%20use%20the%20Microsoft%20Graph%20in%20PS%20to%20be%20able%20to%20add%20team%20members%3C%2FLINGO-BODY%3E
Deleted
Not applicable

Is there a powershell script to add exiting AD users/members to Exisitng Teams?

14 Replies
My understanding is that you will have to use the Microsoft Graph in PS to be able to add team members

You should be able to do it via regular cmdlets too, i.e.

 

Add-UnifiedGroupLinks -Identity team -LinkType Member -Links user@domain.com

 

However things happen slooooooow with this approach, so Graph should be better I guess.

FYI, MS just announced that some groups for certain Managers and their Direct Reports will be getting created automatically to, see https://support.office.com/en-us/article/Manage-automatic-creation-of-direct-reports-group-Admin-hel....

 

THis may be helpful

 

I dont believe I have the option of using the Microsoft Graph API yet. We dont have any Azure accounts as well as i'm not quite sure how to do any of that. I still just connect to Office365 through a Azure Active Directory Module for Powershell

 

Thank you for the cmdlet - That did work. Is there anyway to also set the role as well for the user? (Owner/Member)

Solution

Yes, all roles are different "link" types:

 

Add-UnifiedGroupLinks -Identity team -LinkType Owner -Links user@domain.com

Dynamic group creation has been delayed and rolled out to a select set of customers first to gather more feedback. https://techcommunity.microsoft.com/t5/Office-365-Groups/Update-Auto-creation-of-Direct-Reports-grou...

 

is there a difference between this Unified Group and the Azure AD powershell Add-AzureADGroupMember cmdlet, for example? I just did some tests with the AAD powershell and that managed to work for editing membership of a MS Team (supported by its underlying O365 group). I was just curious what capabilities or what is different with this UnifiedGroup cmdlet I see mentioned here and on some MS blogs.   Thanks!

@Sonia Cuff is there any news about MS Teams supporting dynamic (attribute-based) memberships now, or soon in the future? 

Teams members are stored in Azure AD groups, those can be populated dynamically if you have Azure AD P2 licenses, see https://docs.microsoft.com/en-us/azure/active-directory/active-directory-groups-dynamic-membership-a...

 

Thanks very much Dean for the link, I've read that article before but appears to have some new information in there. Actually turns out it's just P1 to support dynamic groups as well which is a plus, (which luckily I have) but now working out the dynamics of using powershell with custom functions, it's not standard cmdlets to enable this in powershell.

Cheers!

I have an open Premier case about this capability.   The case notes say that our issue appears to be "enableDynamicMembershipTeams value is set to False for tenant".  This gives me hope that this capability will be available soon.   It would still require a AD PRemeium license though.

Yes : 

 

Connect-MicrosoftTeam

Add-TeamUser -GroupId $($TheTeam.GroupId) -Role Owner/Member -User $UserPrincipalName

Disconnect-MicrosoftTeams

Have you ever tried the below example before? When i do, the owner that is added is not able to add apps to the new Team, where as anyone else added as a owner / member from the front end is able to

Scenario :

Create a New Team Via Powershell (Service Account)
Add another Owner
Go to front interface and install apps... result fails to install