Get-Set Choice Field Value in SharePoint using PowerShell

Here is my nifty collection of PowerShell scripts to read or update values in Choice column 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="http://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 choice field value programmatically using this PowerShell script.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$WebURL="http://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 choice column

#Define URL and List name variables 
$WebURL="http://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 value of 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="http://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 is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

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

  • August 29, 2019 at 3:11 PM

    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
  • April 23, 2019 at 2:20 AM

    Thank you. understood.

    Reply
  • April 22, 2019 at 6:16 AM

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

    Reply
  • April 22, 2019 at 6:03 AM

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

    Reply
  • April 22, 2019 at 1:31 AM

    The value can not be reflected in sharepoint online ?

    Reply
  • December 24, 2018 at 8:40 AM

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

    Reply

Leave a Reply