Load SharePoint CSOM assemblies in beginning:
Add-Type -Path (Resolve-Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll")
Add-Type -Path (Resolve-Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll")
And try to initialize $UserCollection
as below in your code:
$UserCollection = @()
foreach($UserAccount in $UserAccountsColl)
{
#Get the User
$User=$web.EnsureUser($UserAccount)
$spuserValue = New-Object Microsoft.SharePoint.Client.FieldUserValue
$spuserValue.LookupId = $User.id
$UserCollection += $spuserValue
}
$userValueCollection = [Microsoft.SharePoint.Client.FieldUserValue[]]$UserCollection
#update the Multiple value Person or Group field
$ListItem[$FieldName] = $userValueCollection
$ListItem.Update()
$ClientContext.ExecuteQuery()
Hope this will help you.