Create New MS Teams Site: Add-TeamUser Throws Error

I am fairly new to PowerShell and I am running a PowerShell script to create a MS Teams site, create channels, and assign an owner. When I run the script, it is successful (even the owner is successfully assigned) but throws an error.

# Set vars
$TeamName = "Site Name"
$TeamDescription = "Description text goes here"
$TeamVisibility = "Private"
$TeamOwner = ""

# Connect to Teams

Start-Sleep -Second 10

# Create new Teams Site
$group = New-Team -DisplayName "$TeamName" -Description "$TeamDescription" -Visibility "$TeamVisibility"

Start-Sleep -Second 45

# Add users, set permissions
Add-TeamUser -GroupId $group.GroupId -User "$TeamOwner" -Role Owner

The above line throws an error:

Add-TeamUser : Error occurred while executing Add-TeamUser
Code: Request_BadRequest
Message: One or more added object references already exist for the following modified properties: ‘owners’.
RequestId: 51eeff26-95e2-48a3-8310-836fafa156be
DateTimeStamp: 2019-06-20T13:07:17
HttpStatusCode: Request_BadRequest
At line:18 char:1

  • Add-TeamUser -GroupId $group.GroupId -User “$TeamOwner” -Role Owner
  • CategoryInfo : NotSpecified: (:slight_smile: [Add-TeamUser], ApiException
  • FullyQualifiedErrorId : Microsoft.TeamsCmdlets.PowerShell.Custom.ErrorHandling.ApiException,Microsoft.TeamsCmdlets.PowerShell.Custo