Get-Set Choice Field Value in SharePoint using PowerShell

In SharePoint, a Choice field is one in which you can select from a predefined list of values. Sometimes, You may need to retrieve or update the value for a Choice field using PowerShell. In this blog post, we’ll show you how to do that.

Here is my nifty collection of PowerShell scripts to read or update the Choice column values in SharePoint:

sharepoint powershell to read update choice field value

SharePoint: PowerShell to Get Choice Field Value

PowerShell to get choice field values:

#Define URL and List name variables 
$WebURL="https://intranet.crescent.com/"
$ListName ="Projects"

$Web = Get-SPWeb $WebURL
$List = $Web.lists.TryGetList($ListName)

#Get the 1st item stored in the list
$Item = $list.items[0]

#Get the formatted value of "Department" choice column
Write-host "Choice Field Value:" $item.GetFormattedValue("Department")

PowerShell to Get Multiple Choices Field Value

We can get the choice field value programmatically using this PowerShell script.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$WebURL="https://intranet.crescent.com/"
$ListName ="Projects"
$MultiChoiceFieldName="Category"

$Web = Get-SPWeb $WebURL
$List = $Web.lists.TryGetList($ListName)
#Get the 1st item stored in the list
$Item = $List.items[0]

#Get the multiple choice field 
$MultiChoiceValues = New-Object Microsoft.SharePoint.SPFieldMultiChoiceValue($Item[$MultiChoiceFieldName])

#Print Each Value
For($I=0; $I -lt $MultiChoiceValues.count; $I++)
{            
 write-host $MultiChoiceValues[$I]
}

SharePoint: Set Choice Field Value using PowerShell

This PowerShell script adds value to the choice column.

#Define URL and List name variables 
$WebURL="https://sharepoint.crescent.com/sites/Operations/"
$ListName ="List Versions"

#Get the Web and Lists objects
$web = Get-SPWeb $WebURL
$List = $web.Lists[$ListName]

#Add new Get the 1st item stored in the list
$Item = $list.AddItem()
$item["Title"] = "Test001" #Set Mandatory title field
#sharepoint 2010 powershell update choice field
$item["Department"] = "Sales"
$item.Update(

Set Multi-Choice Field value using PowerShell:

This sets multi-choice field programmatically.

#Add new Get the 1st item stored in the list
$Item = $list.AddItem()
$item["Title"] = "Test009"

#Set Choice values
$choicevalues = New-Object Microsoft.SharePoint.SPFieldMultiChoiceValue
$choicevalues.Add("Sales")            
$choicevalues.Add("Purchase")    

$list.Fields["Department"].ParseAndSetValue($item,$choicevalues)

#Commit changes
$item.Update()

This sets the value of a choice field.

Update Choice Field Check boxes (allow multiple selections) Values:

Here is another method to set multi-choice column. 

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Define URL and List name variables 
$WebURL="https://portal.crescent.com/sites/ops"
$ListName ="News"
 
#Get the Web and List and Item objects
$web = Get-SPWeb $WebURL
$List = $web.Lists[$ListName]
$Item = $List.GetItemById(1)

#Set Choice values
$choicevalues = New-Object Microsoft.SharePoint.SPFieldMultiChoiceValue
$choicevalues.Add("News")            
$choicevalues.Add("Flash News")    

#sharepoint Powershell to update choice field
$item["Category"] = $Choicevalues
$item.Update()

Write-host "Choice field values updated for item!"

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

7 thoughts on “Get-Set Choice Field Value in SharePoint using PowerShell

  • How would l update the choice associated to content type as the changes have been made locally to the list but not to the content type

    Reply
  • Thank you. understood.

    Reply
  • SharePoint Online: Is this a problem? Type [Microsoft.SharePoint.SPFieldMultiChoiceValue] not found

    Reply
  • I can not use “.ParseAndSetValue” with sharepoint online.

    Reply
  • The value can not be reflected in sharepoint online ?

    Reply
  • Good post! I definitely learn something new and challenging on a daily basis from your blog, Thanks a bunch buddy.

    Reply

Leave a Reply

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