Feb 15 2019 07:37 AM - edited Feb 19 2019 01:27 AM
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!
Feb 18 2019 04:55 AM - edited Feb 18 2019 04:56 AM
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.
Feb 18 2019 05:39 AM
Hi Thomas,
Yeah I've done it before, my script below is still causing an error:
Feb 18 2019 06:27 AM - edited Feb 18 2019 06:29 AM
What error are you getting and where is it failing?
Also, to access that field, try $salesmangers = $ListItem.FieldValues.SalesManager.Email
Feb 19 2019 01:24 AM
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.
Feb 19 2019 08:16 AM - edited Feb 19 2019 08:18 AM
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.
Feb 20 2019 01:28 AM
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....
Feb 20 2019 01:28 AM
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!
Feb 20 2019 02:07 AM
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.
Feb 20 2019 02:14 AM - edited Feb 20 2019 02:15 AM
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}
Feb 20 2019 02:51 AM
Yeah basically.
What I've used before and worked fine.
Your script below worked perfectly!