Forum Discussion
Adding user to a Multivalued person field SPO Powershell
Hi SharePoint Users,
I'm trying to add multiple users to a person field using the code below. I get the error -
Cannot find type [Microsoft.SharePoint.SPFieldUserValueCollection]: verify that the assembly containing this type is loaded.
I'm using SPO management shell to run the script
Any help appreciated.
Regards,
Kevin
[Microsoft.SharePoint.SPFieldUserValueCollection]$lotsofpeople = New-Object Microsoft.SharePoint.SPFieldUserValueCollection
$FirstUser =$ClientContext.Web.EnsureUser("i:0#.f|membership|"+ "****@***.com")
$FirstUserValue = New-Object Microsoft.SharePoint.SPFieldUserValue($ClientContext, $FirstUser.Id, $FirstUser.LoginName)
$lotsofpeople.Add($FirstUserValue);
$ListItem["Multivalued"]=[Microsoft.SharePoint.SPFieldUserValueCollection] $lotsofpeople
$ListItem.Update()
$ClientContext.ExecuteQuery()
2 Replies
- How are you loading SPO assemblies in your script?
- kevingeorgetBrass Contributor
with the below code. The folder has the 3 Dll's
$dllDir="D:\SharePointDll"
try{
Add-Type -Path ("$dllDir\Microsoft.SharePoint.Client.dll") | Out-Null
Add-Type -Path ("$dllDir\Microsoft.SharePoint.Client.Runtime.dll") | Out-Null
Add-Type -Path ("$dllDir\Microsoft.SharePoint.Client.Publishing.dll")|Out-Null
}
catch{
Log "Error: $($_.Exception.Message) $((get-date -format G))"
}