I would like to add some users to a people or groups field of a custom list with PowerShell? How can I do that?


1 Answer 1

[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);            
$i["lotsofpeoplefield"] = $lotsofpeople;            

Where $i is the list item to update. $w is the SPWeb object.

Reference - http://social.technet.microsoft.com/wiki/contents/articles/20831.sharepoint-a-complete-guide-to-getting-and-setting-fields-using-powershell.aspx#Set_and_Get_a_Multi-Person_Field


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.