Adding team members by powershell script

HASSAN BIN NASIR DAR 306 Reputation points


I have 105 Microsoft teams.

Every teams has random members. Some teams have 10 members , some have 50 and some have 40 etc

Now I have Migrated all teams from the source to destination tenant. Teams are migrated successfully. But Members and owner could not transfer because source domain is not available on destination tenant so thats why account could not find out.

My all users have accounts with destination domain.

Now I want to add members for each teams manually by powershell script. Can you help me to provide script?

Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,034 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sharon Zhao-MSFT 25,051 Reputation points Microsoft Vendor


    As we are mainly responsible for general question of Microsoft Teams, script is not in our service scope. The following processes just provide ideas and methods. Then, you should combine them together.

    First of all, you should create a UserInfo.csv file which contains all the members and owners corresponding to teams’ GroupId. Save this file in c:\Temp\UserInfo.csv.

    The following image is an example:

    Secondly, Connect to Microsoft Teams module:

    $User =  
    $PassWord = ConvertTo-SecureString -String "**YourPassword**" -AsPlainText -Force  
    $UserCredential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $User, $PassWord  
    import-module microsoftteams  
    Connect-MicrosoftTeams -Credential $UserCredential -AccountId $User  

    At last, using Add-TeamsUser command to add owners and members one by one to teams. A conditional statement is necessary here. The following code snippet is for reference:

    $users = import-csv c:\Temp\UserInfo.csv  
    Foreach($user in $users)  
    Add-TeamUser -GroupId $user.GroupID -User $user.UserID -Role $user.Role  

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.