Add-PnpListItem and Set-PnpListItem Multiple User Field - Adding more than one SharePoint Group

Copper Contributor

When trying to add more than one SharePoint group to a field using either the values in PowerShell Add-PnpListItem or Set-PnpListItem fails to set the user field.


I've tried using the groups ID's in various different formats, but either it fails to set the values, or only sets one of the groups into the field.  For example:


I have a field called "Reviewers"

and two groups with ID (which I get by using Get-PnPGroup):

  1. TA Mangers = 19
  2. QA Officers = 22

According to the docs page for both of those commands:


Person/Group (id of user/group in Site User Info List or email of the user, separate multiple values with a comma): -Values @{"PersonField" = "","21"}


Based on that I've tried all of the following:


$groups = @(19,22)
Set-PnPListItem -List "Policies" -Identity 2 -Values @{"Reviewers"=$groups} #ONLY SETS ONE VALUE
Set-PnPListItem -List "Policies" -Identity 2 -Values @{"Reviewers"="19","22"} #SETS THE LAST ITEM IN THE LIST
#Using the "LoginName" of each group (as they don't have an "Email"
Set-PnPListItem -List "Policies" -Identity 2 -Values @{"Reviewers"="TA Managers","QA Officers"} #Fails with The Specified user TA Managers could not be found
#Using the "LoginName" of each group (as they don't have an "Email"
$groups = @("TA Managers","QA Officers")
Set-PnPListItem -List "Policies" -Identity 2 -Values @{"Reviewers"=$groups} #Fails with The Specified user TA Managers could not be found


Am I doing something wrong when setting these?


Note - i've tried these examples like this, however, in my wider script, i'm using Get-PnPGroup to get all the groups, then for each list item, i'm matching the groups against an input CSV, when i'm getting the group ID's and setting the values.  I can quite happily set a single group, but where I need to set more than 1, it just doesn't play ball.


2 Replies

@Bhayaty It appears there may be a bug in the Set-ListItem code. I've tested a couple scenarios. With two items in the array, it only sets 1 value. When you specify 3 items in an array, it only sets the 1st and the 3rd items, skipping the second. 

You may want to submit an issue in the GitHub Issues list.

@Beau Cameron Thanks for confirming, it was driving me a little crazy as I thought I was doing something wrong, but just good to get some confirmation that there is an issue in the underlying code.


Will post an issue as suggested, I think it may be in one of the underlying repos, rather than the PnP stuff itself, as I have the issue even when using Add-PnPListItem, which I suspect both call the same methods to set the values.