pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
990 stars 663 forks source link

[BUG] Set-PnPUnifiedGroup Throws Error when Setting Owners #2845

Open sympmarc opened 4 years ago

sympmarc commented 4 years ago

Reporting an Issue or Missing Feature

Set-PnPUnifiedGroup -Owners should set the owners based on UPNs provided.

In the docs: "The array UPN values of owners to set to the group. Note: Will replace owners."

Expected behavior

    Connect-PnPOnline -Scopes "Directory.ReadWrite.All", "Group.ReadWrite.All", "User.Read.All"
    $group = Get-PnPMicrosoft365Group -Identity $siteInfo.GroupId.Guid
    $newOwners = "cjordan@foo.com", "kdochney@foo.com", "marc.anderson@foo.com"
    Clear-PnPMicrosoft365GroupOwner -Identity $group # Removes all but one Owner and throws an error
    Set-PnPUnifiedGroup -Identity $group -Owners $newOwners -Members $newOwners 

I expect the three users to be added a both Owners and Members.

Also see: #2820

Actual behavior

If one or more of the UPNs provided are already Owners, this is the error. Based on the docs, I expect all three users to replace whomever is already there.

Set-PnPUnifiedGroup : Code: Request_BadRequest
Message: One or more added object references already exist for the following modified properties: 'owners'.
Inner error
At D:\code\Denholtz\Deployment\PowerShell\ReApplyPnPProvisioningTemplate.ps1:37 char:5
+     Set-PnPUnifiedGroup -Identity $group -Owners $newOwners -Members  ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (PnP.PowerShell....crosoft365Group:SetMicrosoft365Group) [Set-PnPMicrosoft365Group], ServiceException
    + FullyQualifiedErrorId : GROUPUPDATEFAILED,PnP.PowerShell.Commands.Graph.SetMicrosoft365Group

Steps to reproduce behavior

See above

Which version of the PnP-PowerShell Cmdlets are you using?

What is the version of the Cmdlet module you are running?

3.24.2008.0

How did you install the PnP-PowerShell Cmdlets?