Quantcast
Channel: SharePoint Diary
Viewing all articles
Browse latest Browse all 1058

PowerShell to Update Multi-valued Peole Picker Field with New Users

$
0
0
Requirement: Update existing People Picker field value using PowerShell.

PowerShell script to Add an new user to existing People Picker field:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration parameters
$SiteURL = "http://portal.crescent.com/projects/"
$ListName = "Projects"
$FieldName= "ProjectTeamMembers"
$UserToAdd="Crescent\Faris"
$ItemID=431

#Get site and List objects
$web = Get-SPWeb $SiteURL
$List = $web.Lists.TryGetList($ListName)

if($List -ne $null)
{
#Get the Item
$Item = $List.GetItembyID($ItemID)

#Get Existing field value
$MultiUserCollection = [Microsoft.SharePoint.SPFieldUserValueCollection]$item[$FieldName]

#Prepre the user to add
$User = $Web.EnsureUser($UserToAdd)
$NewUser = new-object Microsoft.SharePoint.SPFieldUserValue($Web, $User.ID, $User.LoginName)

#Update Multivalued people Picker field
$MultiUserCollection.Add($NewUser)
$item[$FieldName] = $MultiUserCollection
$item.update()
}
write-host "New User Added and Existing People Picker field value updated!"

Viewing all articles
Browse latest Browse all 1058

Trending Articles