Set-PnPListItem - Multiple User Field

%3CLINGO-SUB%20id%3D%22lingo-sub-343664%22%20slang%3D%22en-US%22%3ESet-PnPListItem%20-%20Multiple%20User%20Field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-343664%22%20slang%3D%22en-US%22%3E%3CP%3EHey%20Folks%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETrying%20to%20update%20a%20List%20item%20via%20PowerShell%2C%20the%20column%20is%20a%20multiple%20user%20field.%3C%2FP%3E%3CP%3EThe%20updated%20users%20are%20currently%20in%20an%20array%20of%20Email%20Addresses%20which%20is%20causing%20an%20error.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWondering%20if%20anyone%20knows%20how%20I%20could%20easily%20convert%20this%20to%20a%20string%20or%20if%20there's%20a%20workaround%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-343664%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ELists%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPnP%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-353909%22%20slang%3D%22en-US%22%3ERe%3A%20Set-PnPListItem%20-%20Multiple%20User%20Field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-353909%22%20slang%3D%22en-US%22%3E%3CP%3EYeah%20basically.%3C%2FP%3E%3CP%3EWhat%20I've%20used%20before%20and%20worked%20fine.%3CBR%20%2F%3E%3CBR%20%2F%3EYour%20script%20below%20worked%20perfectly!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-353893%22%20slang%3D%22en-US%22%3ERe%3A%20Set-PnPListItem%20-%20Multiple%20User%20Field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-353893%22%20slang%3D%22en-US%22%3E%3CP%3EWhat%20exactly%20are%20you%20trying%20to%20do%20with%20the%20Where-Object%3F%20Are%20you%20basically%20looking%20to%20remove%20an%20email%20address%20that%20matches%20%22%24currentmanager%22%20from%20that%20array%20before%20adding%20it%20to%20the%20List%20Item%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETry%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CSPAN%3E%24newlistofmanagers%3C%2FSPAN%3E%20%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%20%40()%0A%20%20%20%20%3C%2FSPAN%3E%3CSPAN%3Eforeach%3C%2FSPAN%3E%3CSPAN%3E%20(%3C%2FSPAN%3E%3CSPAN%3E%24manager%3C%2FSPAN%3E%20%3CSPAN%3Ein%3C%2FSPAN%3E%20%3CSPAN%3E%24salesmanagers%3C%2FSPAN%3E%3CSPAN%3E)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%3C%2FSPAN%3E%3CSPAN%3Eif%3C%2FSPAN%3E%3CSPAN%3E%20(%3C%2FSPAN%3E%3CSPAN%3E%24manager%20%3C%2FSPAN%3E%3CSPAN%3E-ne%3C%2FSPAN%3E%20%3CSPAN%3E%24currentmanager%3C%2FSPAN%3E%3CSPAN%3E)%0A%20%20%20%20%20%20%20%20%7B%3C%2FSPAN%3E%0A%20%20%20%20%20%20%3CSPAN%3E%24newlistofmanagers%20%3C%2FSPAN%3E%3CSPAN%3E%2B%3D%3C%2FSPAN%3E%20%3CSPAN%3E%24manager%3C%2FSPAN%3E%3CSPAN%3E%20%20%20%20%20%20%20%20%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%3CBR%20%2F%3E%3CBR%20%2F%3ESet-PnPListItem%20-List%20%24customerlistID%20-Identity%20%24ListItem.ID%20-Values%20%40%7B%22SalesManager%22%20%3D%20%24newlistofmanagers%7D%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-353891%22%20slang%3D%22en-US%22%3ERe%3A%20Set-PnPListItem%20-%20Multiple%20User%20Field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-353891%22%20slang%3D%22en-US%22%3E%3CP%3ESeems%20to%20be%20%22%20%3CFONT%3E%7C%20Where-Object%20%7B%20%24_%20%E2%80%93ne%20%24currentmanger%20%7D%20%3C%2FFONT%3E%22%20that%20is%20causing%20the%20error.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20I%20run%26nbsp%3B%3CFONT%3E%24newmanagerslist%20%2B%3D%20%24salesmanger%3C%2FFONT%3E%20then%20the%20Set-PnPListItem%2C%20it%20works%20as%20expected.%3C%2FP%3E%3CP%3ENot%20sure%20how%20else%20to%20remove%20an%20item%20from%20an%20Array%20as%20.Remove(%22%22)%20is%20not%20supported.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-353876%22%20slang%3D%22en-US%22%3ERe%3A%20Set-PnPListItem%20-%20Multiple%20User%20Field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-353876%22%20slang%3D%22en-US%22%3E%3CP%3EChecked%20the%20array%2C%20but%20looks%20fine%20with%20valid%20email%20addresses.%3C%2FP%3E%3CP%3E%3CSPAN%3E%24newlistofmanagers%3C%2FSPAN%3E.GetType()%20also%20returns%20as%20an%20array%20as%20well%20so%20not%20sure%20what's%20happening!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-353875%22%20slang%3D%22en-US%22%3ERe%3A%20Set-PnPListItem%20-%20Multiple%20User%20Field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-353875%22%20slang%3D%22en-US%22%3E%3CP%3EChecked%20the%20array%2C%20but%20looks%20fine%20with%20valid%20email%20addresses.%3C%2FP%3E%3CP%3E%3CSPAN%3E%24newlistofmanagers%3C%2FSPAN%3E.GetType()%20also%20returns%20as%20an%20array%20as%20well%20so%20not%20sure%20what's%20happening....%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-353240%22%20slang%3D%22en-US%22%3ERe%3A%20Set-PnPListItem%20-%20Multiple%20User%20Field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-353240%22%20slang%3D%22en-US%22%3E%3CP%3ETry%20checking%20your%20%24newlistofmanagers%20before%20passing%20it%20into%20Set-PnPListItem%2C%20and%20check%20%24newmanager%20to%20make%20sure%20they%20look%20right.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESomething%20must%20be%20going%20wrong%20somewhere%20along%20the%20line%20of%20building%20that%20array%2C%20since%20an%20array%20of%20valid%20email%20addresses%20will%20work%20with%20that%20cmdlet%20no%20problem.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-352949%22%20slang%3D%22en-US%22%3ERe%3A%20Set-PnPListItem%20-%20Multiple%20User%20Field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-352949%22%20slang%3D%22en-US%22%3E%3CP%3EError%20is%3A%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%3ESet-PnPListItem%20%3A%20The%20specified%20user%26nbsp%3B%20could%20not%20be%20found.%3CBR%20%2F%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELine%3A%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%3ESet-PnPListItem%20-List%20%24customerlistID%20-Identity%20%24ListItem.ID%20-Values%20%40%7B%22SalesManager%22%20%3D%20%24newlistofmanagers%7D%20%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%3ESwapping%20to%20FieldValues%3CSPAN%3E.SalesManager.Email%3C%2FSPAN%3E%20made%20no%20difference%20either.%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-352520%22%20slang%3D%22en-US%22%3ERe%3A%20Set-PnPListItem%20-%20Multiple%20User%20Field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-352520%22%20slang%3D%22en-US%22%3E%3CP%3EWhat%20error%20are%20you%20getting%20and%20where%20is%20it%20failing%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20to%20access%20that%20field%2C%20try%26nbsp%3B%3CSPAN%3E%24salesmangers%20%3D%20%24ListItem.FieldValues.SalesManager.Email%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-352501%22%20slang%3D%22en-US%22%3ERe%3A%20Set-PnPListItem%20-%20Multiple%20User%20Field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-352501%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Thomas%2C%3CBR%20%2F%3E%3CBR%20%2F%3EYeah%20I've%20done%20it%20before%2C%20my%20script%20below%20is%20still%20causing%20an%20error%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3E%3CFONT%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24salesmangers%20%3D%20%24ListItem.SalesManager.Email%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24salesmangers%20%2B%3D%20%24newmanager%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24newlistofmanagers%20%3D%20%24salesmangers%20%7C%20Where-Object%20%7B%20%24_%20%E2%80%93ne%20%24currentmanger%20%7D%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%3E%26nbsp%3B%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set-PnPListItem%20-List%20%24customerlistID%20-Identity%20%24ListItem.ID%20-Values%20%40%7B%22SalesManager%22%20%3D%20%24newlistofmanagers%7D%26nbsp%3B%26nbsp%3B%20%3C%2FFONT%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-352475%22%20slang%3D%22en-US%22%3ERe%3A%20Set-PnPListItem%20-%20Multiple%20User%20Field%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-352475%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Blair%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAn%20array%20of%20email%20addresses%20is%20definitely%20supported.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20just%20tested%20this%20out%20passing%20in%20an%20array%20of%20email%20address%20strings%20and%20it%20worked%20fine.%20Here's%20the%20exact%20syntax%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24users%20%3D%20%22user%40contoso.com%22%2C%20%22user2%40contoso.com%22%3C%2FP%3E%3CP%3EConnect-PnPOnline%20-Url%20%3CA%20href%3D%22https%3A%2F%2Fcontoso.sharepoint.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fcontoso.sharepoint.com%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESet-PnPListItem%20-List%20%22test1%22%20-Identity%201%20-Values%20%40%7B%22TestPeopleMulti%22%3D%24users%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20updated%20the%20user-multi%20field%20with%20both%20users.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor

Hey Folks,

 

Trying to update a List item via PowerShell, the column is a multiple user field.

The updated users are currently in an array of Email Addresses which is causing an error.

 

Wondering if anyone knows how I could easily convert this to a string or if there's a workaround?

 

Thanks!

10 Replies

Hi Blair,

 

An array of email addresses is definitely supported.

 

I just tested this out passing in an array of email address strings and it worked fine. Here's the exact syntax:

 

$users = "user@contoso.com", "user2@contoso.com"

Connect-PnPOnline -Url https://contoso.sharepoint.com

 

Set-PnPListItem -List "test1" -Identity 1 -Values @{"TestPeopleMulti"=$users}

 

This updated the user-multi field with both users.

 

Hi Thomas,

Yeah I've done it before, my script below is still causing an error:

 

    $salesmangers = $ListItem.SalesManager.Email
    $salesmangers += $newmanager
    $newlistofmanagers = $salesmangers | Where-Object { $_ –ne $currentmanger }
  
    Set-PnPListItem -List $customerlistID -Identity $ListItem.ID -Values @{"SalesManager" = $newlistofmanagers}  

What error are you getting and where is it failing?

 

Also, to access that field, try $salesmangers = $ListItem.FieldValues.SalesManager.Email

Error is: 

Set-PnPListItem : The specified user  could not be found.

 

Line: 

Set-PnPListItem -List $customerlistID -Identity $ListItem.ID -Values @{"SalesManager" = $newlistofmanagers}

 

Swapping to FieldValues.SalesManager.Email made no difference either.

Try checking your $newlistofmanagers before passing it into Set-PnPListItem, and check $newmanager to make sure they look right.

 

Something must be going wrong somewhere along the line of building that array, since an array of valid email addresses will work with that cmdlet no problem.

Checked the array, but looks fine with valid email addresses.

$newlistofmanagers.GetType() also returns as an array as well so not sure what's happening....

Checked the array, but looks fine with valid email addresses.

$newlistofmanagers.GetType() also returns as an array as well so not sure what's happening!

Seems to be " | Where-Object { $_ –ne $currentmanger } " that is causing the error.

 

If I run $newmanagerslist += $salesmanger then the Set-PnPListItem, it works as expected.

Not sure how else to remove an item from an Array as .Remove("") is not supported.

What exactly are you trying to do with the Where-Object? Are you basically looking to remove an email address that matches "$currentmanager" from that array before adding it to the List Item?

 

Try this:

 

$newlistofmanagers = @()
    foreach ($manager in $salesmanagers)
    {
        if ($manager -ne $currentmanager)
        {
      $newlistofmanagers += $manager        
} }

Set-PnPListItem -List $customerlistID -Identity $ListItem.ID -Values @{"SalesManager" = $newlistofmanagers}

 

 

Yeah basically.

What I've used before and worked fine.

Your script below worked perfectly!