Sunday, December 27, 2015

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

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 = ""
$ListName = "Projects"                
$FieldName= "ProjectTeamMembers"

#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 
        $item[$FieldName] = $MultiUserCollection
write-host "New User Added and Existing People Picker field value updated!"     

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...