How to add members in teams for via PowerShell

Dharmendra Mudliar 21 Reputation points
2022-02-16T01:06:42.667+00:00

Scenario:
I'm trying to create a new Team via below cmdlet and adding individual users.
a. $userAlias1 = "xxxx.microsoft.com"
b. $groupId = New-Team -displayName $teamsGroupName -Visibility "private" -Owner "dxxxx@Company portal .com"
c. Add-TeamUser -GroupId $groupId.GroupId -User $userAlias1

Question:

  1. How to add members in teams via PowerShell. I want to add all users from a Security Group - "AAAA" to the new Team I'm creating above?
Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,913 questions
0 comments No comments
{count} votes

Accepted answer
  1. Manu Philip 18,071 Reputation points MVP
    2022-02-16T02:56:14.67+00:00

    I tested the following script and works well. You may substituting your own values and proceed with the same script

    $userAlias1 = "manu1@cloudcompute.info"
    $DisplayName = "Test Team Group"
    $teamsGroupName = "TestTeam"
    $group = New-Team -DisplayName $teamsGroupName -MailNickname $teamsGroupName -Visibility "private" -Owner "manu@cloudcompute.info"
    Add-TeamUser -GroupId $group.GroupId -User $userAlias1
    

    If the Answer is helpful, please click "Accept Answer" and upvote it


1 additional answer

Sort by: Most helpful
  1. Yuki Sun-MSFT 41,041 Reputation points Microsoft Vendor
    2022-02-16T08:25:27.54+00:00

    Hi @Dharmendra Mudliar ,

    How to add members in teams via PowerShell. I want to add all users from a Security Group - "AAAA" to the new Team I'm creating above?

    Based on my test, you can try the using the steps and scripts below:

    1. Connect to both the Teams powershell and Exchange Online powershell.
    2. Run the following scripts below after replacing the values with yours.:
      $teamsGroupName = "TestTeam"  
      $groupId = New-Team -displayName $teamsGroupName -Visibility "private" -Owner "owner@contoso.com"  
      Get-DistributionGroupMember "AAAA" | foreach{Add-TeamUser -GroupId $groupId.GroupId -user $_.PrimarySmtpAddress}  
      

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.