I have a CSV file which contains semicolon-separated Values to a certain field:
Reviewer
domain\userOne;domain\userTWO
In PowerShell (CSOM - executed on my local computer) I am grabbing this data and write it to a list item in SharePoint. The relevant part of the script is:
$Reviewer = $_.Reviewer
$ReviewerTEST = $Reviewer.Split(";")
## Define empty array
$lookupValueCollection = @()
ForEach($ReviewerSolo in $ReviewerTEST){
Write-Host "$ReviewerSolo"
$SPUser = $Context.Web.EnsureUser($ReviewerSolo)
$Context.Load($SPUser)
$Context.ExecuteQuery()
If ($SPUser -ne $Null)
{
$SPUserValue = New-Object Microsoft.SharePoint.Client.FieldUserValue
$SPUserValue.LookupId = $SPUser.id
##Write-Host "$SPUser.id"
$lookupValueCollection += $SPUserValue
Write-Host "$lookupValueCollection"
}
}
If ($lookupValueCollection.length -gt 0)
{
$userValueCollection = [Microsoft.SharePoint.Client.FieldUserValue[]]$lookupValueCollection
$item["Reviewer"] = $userValueCollection
$item.Update()
$Context.ExecuteQuery()
}
I have experienced, that only the first person (domain\userOne) is written into the multi-value person field. After adding a third user to the CSV-File I have experienced, that the first and third person is written to the metadata of the item. It generally seems that only every second person is added, so: first, third, fifth, seventh, and so on. I hope someone of you out there can help me :)
Update: 03.12.2019:
$userValueCollection
for sure contains both users, because when I use:
$item["Reviewer"] = $userValueCollection[0]
then domain\userOne
is written into the SharePoint-field - and when I use:
$item["Reviewer"] = $userValueCollection[1]
then domain\userTwo
is written into the SharePoint-field.
It seems that SharePoint can only handle every 2nd person written to the field.
The field is in a document library.