使用 Powershell 和 TaskManager 在 Sharepoint 中设置多用户字段

Set Multi-User Field in Sharepoint using Powershell and TaskManager

我正在使用 Powershell 在 Sharepoint 中使用以下命令 set/update 多用户字段:

[Microsoft.SharePoint.SPFieldUserValueCollection]$lotsofpeople = New-Object Microsoft.SharePoint.SPFieldUserValueCollection            
$user1 = $w.EnsureUser("domain\user1");            
$user1Value = New-Object Microsoft.SharePoint.SPFieldUserValue($w, $user1.Id, $user1.LoginName)            
$user2 = $w.EnsureUser("domain\user2");            
$user2Value = New-Object Microsoft.SharePoint.SPFieldUserValue($w, $user2.Id, $user2.LoginName);            
$lotsofpeople.Add($user1Value);            
$lotsofpeople.Add($user2Value);            
$i["lotsofpeoplefield"] = $lotsofpeople;            
$i.SystemUpdate($false);

这在 PS 编辑器中效果很好,但是一旦我在 Win TaskManager 中将其设置为重复任务,它就会对所有项目失败,其中 SPFieldUserValueCollection 包含超过 1 个用户。错误:"Invalid look-up value. A look-up field contains invalid data. Please check the value and try again."

有什么想法吗?

今天遇到了同样的问题,我花了一些时间才解决。

显式转换为我解决了问题:

$i["lotsofpeoplefield"] = [Microsoft.SharePoint.SPFieldUserValueCollection] $lotsofpeople
$i.SystemUpdate($false);