Я хочу добавить нескольких пользователей в поле выбора человека в списке SharePoint.Я попробовал приведенный ниже код, но всегда получаю сообщение об ошибке:
Новый объект: не удается найти тип [Microsoft.SharePoint.SPFieldUserValueCollection]: убедитесь, что сборка, содержащая этот тип, загружена.
Может кто-нибудь помочь мне решить эту проблему?
$ClientContext = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Securedpw = ConvertTo-SecureString $Password -AsPlainText -Force
$ClientContext.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $Securedpw)
$web = $ClientContext.Web
$list= $web.lists.GetByTitle($listName)
$ClientContext.Load($list)
$ClientContext.ExecuteQuery()
$ListItemCreationInformation = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$ListItem= $list.AddItem($ListItemCreationInformation)
$UserAccounts="domain\arzoo; domain\ashwin"
$UserAccountsColl = $UserAccounts -split ';'
$UserCollection = new-object Microsoft.SharePoint.SPFieldUserValueCollection
foreach($UserAccount in $UserAccountsColl)
{
#Get the User
$User=$web.EnsureUser($UserAccount)
#Add to collection
$UserFieldValue = new-object Microsoft.SharePoint.SPFieldUserValue($Web, $User.ID, $User.LoginName)
$UserCollection.Add($UserFieldValue)
}
#update the Multiple value Person or Group field
$ListItem[$FieldName] = $UserCollection
$ListItem.Update()