Get-Set Person or Group (People Picker) Field Value using PowerShell in SharePoint

Requirement: SharePoint PowerShell to get and set person or group field value

Person or Group column in SharePoint captures user values. Here is my collection of PowerShell scripts to work with people picker field values:

Get Person or Group People Picker Field Value using PowerShell in SharePoint

Read People Picker Field Value using PowerShell:

Here is the PowerShell script to get the value of a Person or Group field.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Variables
$SiteURL = "https://portal.crescent.com/sites/Sales"
$ListName = "Tasks"                
$FieldName="Assigned To"
 
#Get site and List objects
$web = Get-SPWeb $SiteURL
$list= $web.lists[$listName]

#Iterate through each row in the list
foreach ($Item in $list.Items)
{
    #Get the People picker field value
    $AssignedTo = New-Object Microsoft.Sharepoint.SPFieldUserValue($Web,$Item[$FieldName])

    #Get the Login Name of the user
    Write-host $AssignedTo.User.LoginName
    #Get the Email
    Write-host $AssignedTo.User.Email
}

Get Multi-valued People Picker Field Value (If Allow multiple selections enabled) using PowerShell:

SharePoint PowerShell to get person or group field.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Variables
$SiteURL = "https://portal.crescent.com/sites/Sales"
$ListName = "Tasks"                
$FieldName="Assigned To"
 
#Get site and List objects
$web = Get-SPWeb $SiteURL
$list= $web.lists[$listName]

#Iterate through each row in the list
foreach ($Item in $list.Items)
{
    if($item[$FieldName])
    {
        #Get People picker field values collection
        $UserCollection = New-Object Microsoft.Sharepoint.SPFieldUserValueCollection($Web,$item[$FieldName].ToString())
        Write-host Item ID: $item["ID"]
        
        #Get each User from the Person or Group field
        foreach($User in $UserCollection)
        {
             #Get the Display Name of the user
             Write-host $User.LookupValue 
             #Get the Login Name (Account ID)
             Write-host $User.User
             #Get the E-mail
             Write-host $User.User.Email             
        }
    }
}

PowerShell script to Update Person or Group Field

Let’s set the person or group field using PowerShell in SharePoint:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Variables
$SiteURL = "https://portal.crescent.com/sites/Sales"
$ListName = "Tasks"                
$FieldName="Assigned To"
 
#Get site and List objects
$web = Get-SPWeb $SiteURL
$list= $web.lists[$listName]

#Get the List Item to update
$ListItem  = $List.GetItemByID(2)

#User Account to set
$UserAccount="Crescent\Salaudeen"
#To Add new List Item, use $Item = $List.AddItem()
$User = Get-SPUser -Identity $UserAccount -Web $web
$ListItem[$FieldName] = $User
$ListItem.Update()

Update Multiple Values People Picker Field using PowerShell script

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Variables
$SiteURL = "https://portal.crescent.com/sites/Sales"
$ListName = "Tasks"                
$FieldName="Assigned To"
 
#Get site and List objects
$web = Get-SPWeb $SiteURL
$list= $web.lists[$listName]

#Get the List Item to update
$ListItem  = $List.GetItemByID(2)

#User Account to set
$UserAccounts="Crescent\Salaudeen; Crescent\Ravi"
$UserAccountsColl = $UserAccounts -split ';'

$UserCollection = new-object Microsoft.SharePoint.SPFieldUserValueCollection
foreach($UserAccount in $UserAccountsColl)
{
    #Get the User
    $User=$web.EnsureUser($UserAccount)
    
    #Add to collection
    $UserFieldValue = new-object Microsoft.SharePoint.SPFieldUserValue($Web, $User.ID, $User.LoginName)
    $UserCollection.Add($UserFieldValue)
}

#update the Multiple value Person or Group field
$ListItem[$FieldName] = $UserCollection
$ListItem.Update()

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

5 thoughts on “Get-Set Person or Group (People Picker) Field Value using PowerShell in SharePoint

  • The Update Multiple Values People Picker Field script did not work for me until I changed the $UserCollection to this.
    [Microsoft.SharePoint.SPFieldUserValueCollection]$UserCollection = new-object Microsoft.SharePoint.SPFieldUserValueCollection

    Reply
  • Perfect post, thank you!

    Reply
  • Hi, I am not able to extract people picker values. Getting the error as Cannot find type [Microsoft.Sharepoint.SPFieldUserValue]: verify that the assembly containing this type is loaded.

    Reply
  • How to add multiple groups value in people or group field?

    Reply
  • Goldmine thank you

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *