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

%3CLINGO-SUB%20id%3D%22lingo-sub-1961918%22%20slang%3D%22en-US%22%3EAdd-PnpListItem%20and%20Set-PnpListItem%20Multiple%20User%20Field%20-%20Adding%20more%20than%20one%20SharePoint%20Group%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1961918%22%20slang%3D%22en-US%22%3E%3CP%3EWhen%20trying%20to%20add%20more%20than%20one%20SharePoint%20group%20to%20a%20field%20using%20either%20the%20values%20in%20PowerShell%20Add-PnpListItem%20or%20Set-PnpListItem%20fails%20to%20set%20the%20user%20field.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20tried%20using%20the%20groups%20ID's%20in%20various%20different%20formats%2C%20but%20either%20it%20fails%20to%20set%20the%20values%2C%20or%20only%20sets%20one%20of%20the%20groups%20into%20the%20field.%26nbsp%3B%20For%20example%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20field%20called%20%22Reviewers%22%3C%2FP%3E%3CP%3Eand%20two%20groups%20with%20ID%20(which%20I%20get%20by%20using%20Get-PnPGroup)%3A%3C%2FP%3E%3COL%3E%3CLI%3ETA%20Mangers%20%3D%2019%3C%2FLI%3E%3CLI%3EQA%20Officers%20%3D%2022%3C%2FLI%3E%3C%2FOL%3E%3CP%3EAccording%20to%20the%20docs%20page%20for%20both%20of%20those%20commands%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3EPerson%2FGroup%20(id%20of%20user%2Fgroup%20in%20Site%20User%20Info%20List%20or%20email%20of%20the%20user%2C%20separate%20multiple%20values%20with%20a%20comma)%3A%20-Values%20%40%7B%22PersonField%22%20%3D%20%22user1%40domain.com%22%2C%2221%22%7D%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBased%20on%20that%20I've%20tried%20all%20of%20the%20following%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24groups%20%3D%20%40(19%2C22)%0ASet-PnPListItem%20-List%20%22Policies%22%20-Identity%202%20-Values%20%40%7B%22Reviewers%22%3D%24groups%7D%20%23ONLY%20SETS%20ONE%20VALUE%3C%2FCODE%3E%3C%2FPRE%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3ESet-PnPListItem%20-List%20%22Policies%22%20-Identity%202%20-Values%20%40%7B%22Reviewers%22%3D%2219%22%2C%2222%22%7D%20%23SETS%20THE%20LAST%20ITEM%20IN%20THE%20LIST%3C%2FCODE%3E%3C%2FPRE%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%23Using%20the%20%22LoginName%22%20of%20each%20group%20(as%20they%20don't%20have%20an%20%22Email%22%0ASet-PnPListItem%20-List%20%22Policies%22%20-Identity%202%20-Values%20%40%7B%22Reviewers%22%3D%22TA%20Managers%22%2C%22QA%20Officers%22%7D%20%23Fails%20with%20The%20Specified%20user%20TA%20Managers%20could%20not%20be%20found%3C%2FCODE%3E%3C%2FPRE%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%23Using%20the%20%22LoginName%22%20of%20each%20group%20(as%20they%20don't%20have%20an%20%22Email%22%0A%24groups%20%3D%20%40(%22TA%20Managers%22%2C%22QA%20Officers%22)%0ASet-PnPListItem%20-List%20%22Policies%22%20-Identity%202%20-Values%20%40%7B%22Reviewers%22%3D%24groups%7D%20%23Fails%20with%20The%20Specified%20user%20TA%20Managers%20could%20not%20be%20found%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAm%20I%20doing%20something%20wrong%20when%20setting%20these%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENote%20-%20i've%20tried%20these%20examples%20like%20this%2C%20however%2C%20in%20my%20wider%20script%2C%20i'm%20using%20Get-PnPGroup%20to%20get%20all%20the%20groups%2C%20then%20for%20each%20list%20item%2C%20i'm%20matching%20the%20groups%20against%20an%20input%20CSV%2C%20when%20i'm%20getting%20the%20group%20ID's%20and%20setting%20the%20values.%26nbsp%3B%20I%20can%20quite%20happily%20set%20a%20single%20group%2C%20but%20where%20I%20need%20to%20set%20more%20than%201%2C%20it%20just%20doesn't%20play%20ball.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1961918%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPnP%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1962678%22%20slang%3D%22en-US%22%3ERe%3A%20Add-PnpListItem%20and%20Set-PnpListItem%20Multiple%20User%20Field%20-%20Adding%20more%20than%20one%20SharePoint%20Group%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1962678%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F893171%22%20target%3D%22_blank%22%3E%40Bhayaty%3C%2FA%3E%26nbsp%3BIt%20appears%20there%20may%20be%20a%20bug%20in%20the%20Set-ListItem%20code.%20I've%20tested%20a%20couple%20scenarios.%20With%20two%20items%20in%20the%20array%2C%20it%20only%20sets%201%20value.%20When%20you%20specify%203%20items%20in%20an%20array%2C%20it%20only%20sets%20the%201st%20and%20the%203rd%20items%2C%20skipping%20the%20second.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EYou%20may%20want%20to%20submit%20an%20issue%20in%20the%20GitHub%20Issues%20list.%26nbsp%3B%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fpnp%2FPnP-PowerShell%2Fissues%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fpnp%2FPnP-PowerShell%2Fissues%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
New 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" = "user1@domain.com","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. 
https://github.com/pnp/PnP-PowerShell/issues

@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.