Jul 21 2020 03:24 AM
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.
InnerError:
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 ServiceAccount@evgiii.onmicrosoft.com -GroupId ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-TeamUser], ApiException
+ FullyQualifiedErrorId : Microsoft.TeamsCmdlets.PowerShell.Custom.ErrorHandling.ApiException,Microsoft.TeamsCmdlets.PowerShell.Custom.AddTeamUser
My script looks like this:
Connect-MicrosoftTeams
$groups = Get-Team |Select GroupId, DisplayName
foreach($group in $groups){
Add-TeamUser -User ServiceAccount@evgiii.onmicrosoft.com -GroupId $group.GroupId -Role Owner
}
Jul 22 2020 01:04 AM
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.
Jul 22 2020 01:49 AM
@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.
Sep 09 2021 06:33 AM
@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