Add ServiceAccount member to all teams via Powershell

Iron Contributor

I created a small powershell script to add my ServiceAccount user to all teams via "Add-TeamUser". Unfortunately I get this error message

Add-TeamUser : Error occurred while executing Add-TeamUser
Code: Authorization_RequestDenied
Message: Insufficient privileges to complete the operation.
  RequestId: 25ee1e0c-70cc-44bd-bfe9-b08d5bf05c36
  DateTimeStamp: 2020-07-21T10:19:32
HttpStatusCode: Authorization_RequestDenied
At C:\Users\XYZ\Documents\PSScripts\Others\AddTeamsMember.ps1:5 char:5
+     Add-TeamUser -User -GroupId ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-TeamUser], ApiException
    + FullyQualifiedErrorId : Microsoft.TeamsCmdlets.PowerShell.Custom.ErrorHandling.ApiException,Microsoft.TeamsCmdlets.PowerShell.Custom.AddTeamUser


My script looks like this:

$groups = Get-Team |Select GroupId, DisplayName

foreach($group in $groups){
    Add-TeamUser -User -GroupId $group.GroupId -Role Owner
3 Replies


as per the error message "

Insufficient privileges to complete the operation

user should have admin access to add owner or member to Team. Above command is working fine. Please check is it now working for some teams or all teams you are facing the same issue. You can check GraphApi also to do the above job. 



@teams1535 I used the global admin account for this operation. So this user should be sufficient rights. It worked on all teams that I've checked.
No idea why this error message popped up.

@Thomsch Hi, Was this sorted out for you ? am having the same issue now. earlier this command has worked for me with the same group, and am having sufficient privilege as well