Reputation: 711
Im using the following to set/update a multi user field in Sharepoint using Powershell:
[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);
This works great in the PS Editor but as soon as I set this up as a repeating task in Win TaskManager, it fails for all items, where SPFieldUserValueCollection contains more than 1 user. Error: "Invalid look-up value. A look-up field contains invalid data. Please check the value and try again."
Any ideas?
Upvotes: 2
Views: 3730
Reputation: 76
Had the same problem today and it took me some time to solve it.
An explicitly cast solved the problem for me:
$i["lotsofpeoplefield"] = [Microsoft.SharePoint.SPFieldUserValueCollection] $lotsofpeople
$i.SystemUpdate($false);
Upvotes: 6