Forum Discussion
Thomsch
Jul 21, 2020Iron Contributor
Add ServiceAccount member to all teams via Powershell
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
}
- teams1535Microsoft
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.