SOLVED

Set-SPOListItem with multi-value people column

%3CLINGO-SUB%20id%3D%22lingo-sub-19435%22%20slang%3D%22en-US%22%3ESet-SPOListItem%20with%20multi-value%20people%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-19435%22%20slang%3D%22en-US%22%3E%3CP%3EIf%20I%20do%26nbsp%3BSet-SPOListItem%20with%20string%20variable%20it%20gives%20error.%20Please%20see%20following%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3E%24value%3D%22David%20Longmuir%22%2C%22Conf%20Room%20Stevens%22%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3ESet-SPOListItem%20-List%20%24bidDetailsList%20-Web%20%24web%20-Values%20%40%7B%24key%3D%24value%7D%20-Identity%20%24itemCheck.Id%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EError%3A%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3ESet-SPOListItem%20%3A%20The%20specified%20user%20%22David%20Longmuir%22%2C%22Conf%20Room%20Stevens%22%20could%20not%20be%20found.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20following%20line%20works%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3ESet-SPOListItem%20-List%20%24bidDetailsList%20-Web%20%24web%20-Values%20%40%7B%24key%3D%22David%20Longmuir%22%2C%22Conf%20Room%20Stevens%22%7D%20-Identity%20%24itemCheck.Id%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20is%20the%20best%20way%20to%20set%20the%20multi-value%20people%20field%20using%20a%20variable%3F%20%26nbsp%3BAs%20obviously%20I%20cannot%20hard%20code%20the%20usernames.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-19435%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPnP%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-19502%22%20slang%3D%22en-US%22%3ERe%3A%20Set-SPOListItem%20with%20multi-value%20people%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-19502%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F16139%22%20target%3D%22_blank%22%3E%40Umair%20Naeem%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20got%20this%20to%20work%20by%20doing%20the%20following%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24peopleArr%20%3D%20%40()%3C%2FP%3E%3CP%3E%24peopleArr%20%2B%3D%20%22ben%40mytenant.onmicrosoft.com%22%3CBR%20%2F%3E%24peopleArr%20%2B%3D%20%22chris%40mytenant.onmicrosoft.com%22%3C%2FP%3E%3CP%3E%3CBR%20%2F%3ESet-SPOListItem%20-List%20%22testlist%22%20-Identity%201%20-Values%20%40%7B%22People%22%3D%24peopleArr%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20now%20updated%20my%20blog%20post%20about%20this%20to%20include%20multi%20people%20columns%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fveenstra.me.uk%2F2016%2F06%2F13%2Foffice-365-sharepoint-update-list-items-using-powershell%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fveenstra.me.uk%2F2016%2F06%2F13%2Foffice-365-sharepoint-update-list-items-using-powershell%2F%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-19462%22%20slang%3D%22en-US%22%3ERe%3A%20Set-SPOListItem%20with%20multi-value%20people%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-19462%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20can%20try%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESet-SPOListItem%20-List%20%24bidDetailsList%20-Web%20%24web%20-Values%20%40%7B%24key%3D%24value%7D%20-Identity%20%24itemCheck.Id%3C%2FP%3E%3CP%3E%3CSTRONG%3E%24value%3D%40(%22David%20Longmuir%22%2C%22Conf%20Room%20Stevens%22)%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Visitor

If I do Set-SPOListItem with string variable it gives error. Please see following:

 

$value="David Longmuir","Conf Room Stevens"

Set-SPOListItem -List $bidDetailsList -Web $web -Values @{$key=$value} -Identity $itemCheck.Id

 

Error: Set-SPOListItem : The specified user "David Longmuir","Conf Room Stevens" could not be found.

 

The following line works:

Set-SPOListItem -List $bidDetailsList -Web $web -Values @{$key="David Longmuir","Conf Room Stevens"} -Identity $itemCheck.Id

 

What is the best way to set the multi-value people field using a variable?  As obviously I cannot hard code the usernames.

2 Replies

You can try

 

Set-SPOListItem -List $bidDetailsList -Web $web -Values @{$key=$value} -Identity $itemCheck.Id

$value=@("David Longmuir","Conf Room Stevens")

best response confirmed by Umair Naeem (Visitor)
Solution

Hi @Umair Naeem

 

I got this to work by doing the following:

 

$peopleArr = @()

$peopleArr += "ben@mytenant.onmicrosoft.com"
$peopleArr += "chris@mytenant.onmicrosoft.com"


Set-SPOListItem -List "testlist" -Identity 1 -Values @{"People"=$peopleArr}

 

I've now updated my blog post about this to include multi people columns:

https://veenstra.me.uk/2016/06/13/office-365-sharepoint-update-list-items-using-powershell/