How to update specific cell value in list where cells are multivalue?
-
31-12-2020 - |
Domanda
I want to search for a cell value in a list and only update the match where items are multivalue cells. I'm not sure if my terminology is accurate but I hope I can explain what I mean.
I'm able to search and get a match but updating the values for multivalue cells overwrites all the cell values.
I have a minimal test list with one column: User
This column is of the type 'Person or Group'. In PS the property is called: TypedObject and its value is Microsoft.SharePoint.Client.FieldUser
As this type accepts multiple values (email addresses in my case) I added two users here:
Add-PnPListItem -List $newList -Values @{"User" = "test1@contoso.com","test2@contoso.com"} -ContentTyp Item
If I then try to search for test1@contoso.com and only replace it with test3@contoso.com all the values are replaced, i.e. test2@contoso.com as well:
Get-PnPListItem -List "Test" | Where-Object {$_.FieldValues.User.Email -eq "test1@contoso.com} | Set-PnPListItem -List "Test" -Values @{"User" = "test3@contoso.com"}
The result is that the cell doesn't contain two values (test1@contoso.com, test2@contoso.com) but only test3@contoso.com.
Is there a way to only replace one value instead of all of them?
Thanks a lot in advance.
Soluzione
Set-PnPListItem command is used to update a list item, if you want the updated column contains multiple values, you need to set multiple values in the Set-PnPListItem command.