How to add owners in teams for bulk teams via PowerShell, is there any PowerShell script or any option as we have many teams where we need to change owners and make them as member of those teams?

Vinod Survase 4,781 Reputation points
2021-09-06T15:33:15.583+00:00

How to add owners in teams for bulk teams via PowerShell, is there any PowerShell script or any option as we have many teams where we need to change owners and make them as member of those teams?

Microsoft Teams | Development
Microsoft Teams | Microsoft Teams for business | Other
{count} votes

Accepted answer
  1. Sharon Zhao-MSFT 25,761 Reputation points Microsoft External Staff
    2021-09-07T05:39:30.59+00:00

    @Vinod Survase ,

    Question1. How to add owners in teams for bulk teams via PowerShell

    You can use Add-TeamUser cmdlet to realize your requirement.

    I create a demo as below for reference:

    1. Create a UserInfo.csv file which contains GroupID, UserID and Role as below. Save this file in c:\Temp\UserInfo.csv.
      129776-image.png
    2. Connect to Microsoft Teams module: $User = admin@xxxxxxxxxxxxx .onmicrosoft.com
      $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
    3. Add user as owner in bulk: $users = import-csv c:\Temp\UserInfo.csv
      Foreach($user in $users)
      {
      Add-TeamUser -GroupId $user.GroupID -User $user.UserID -Role $user.Role
      }

    Question 2. is there any PowerShell script or any option as we have many teams where we need to change owners and make them as member of those teams?

    The process is similar with adding owners in teams:

    1. Create a OwnerInfo.csv file which contains GroupID, UserID. Save this file in c:\Temp\OwnerInfo.csv.
    2. Connect to Microsoft Teams module( refer to the step 2 in your first question)
    3. Remove the role owner but stays as a team member: $users = import-csv c:\Temp\OwnerInfo.csv
      Foreach($user in $users)
      {
      Remove-TeamUser -GroupId $user.GroupID -User $user.UserID -Role Owner
      }

    As we are mainly responsible for general question of Microsoft Teams, script is not in our scope. So, I will add office-teams-app-dev tag for further help if possible.


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

    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.

    2 people found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Justin McCaleb 1 Reputation point
    2021-11-17T20:11:04.747+00:00

    Is there a way to add a user to ALL Tenant Teams without adding specific GroupIDs? Or am I missing something here? New to being our Teams Admin, and we have Stakeholders that should be automatically added to every Team created in our org/tenant as Owners.


  2. Vikram 1 Reputation point
    2022-11-24T17:54:24.837+00:00

    All the commands worked @Sharon Zhao-MSFT , thank you. Is there any command to get list of all the Private channels one user is members of. Ex: I need to know user - 123@jaswant .com is member of what Private Channels. And then next day i want to add those same Private Channels to a different user 456@xyz .com.

    0 comments No comments

  3. Jacobo Garrido 0 Reputation points
    2023-07-27T09:48:33.8066667+00:00

    Hello Team,

    Please Could you send us the Script? It is possible? I'm trying but I received some errors.

    Many thanks

    0 comments No comments

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.