Create New MS Teams Site: Add-TeamUser Throws Error

Welcome Forums General PowerShell Q&A Create New MS Teams Site: Add-TeamUser Throws Error

This topic contains 0 replies, has 1 voice, and was last updated by  cmanning96 2 months, 3 weeks ago.

  • Author
    Posts
  • #162909

    Participant
    Topics: 1
    Replies: 0
    Points: 6
    Rank: Member

    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 = "name@name.com"
    
    # Connect to Teams
    Connect-MicrosoftTeams
    
    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'.
    InnerError:
    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: (:) [Add-TeamUser], ApiException
    + FullyQualifiedErrorId : Microsoft.TeamsCmdlets.PowerShell.Custom.ErrorHandling.ApiException,Microsoft.TeamsCmdlets.PowerShell.Custo
    m.AddTeamUser

You must be logged in to reply to this topic.