PowerShell to Get-Set “Yes/No (Check box)” Field Value in SharePoint

Requirement: PowerShell to get or set the Yes/No field value in SharePoint.

sharepoint powershell get set yes no field value

SharePoint: Get Yes/No Field Value using PowerShell

Here is the PowerShell to read Yes/No field programmatically in SharePoint:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set variables
$WebURL="https://intranet.crescent.com"
$ListName ="ProjectTemp"
$FieldName="IsActive" #Internal Name
$ListItemID="1"

#Get Web and List Objects
$Web = Get-SPWeb $WebURL
$List = $Web.Lists[$ListName]

#Get the List Item by ID
$ListItem = $List.GetItembyID($ListItemID)
 
#Get the Yes/No Field Value
$ListItem[$FieldName]

This gets the value of the yes/no field from the given list.

Update Yes/No Field in SharePoint List using PowerShell

Here is the PowerShell to Update the Yes No field SharePoint list programmatically.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set variables
$WebURL="https://intranet.crescent.com"
$ListName ="Projects"
$FieldName="IsActive" #Internal Name
$ListItemID="1"

#Get Web and List Objects
$Web = Get-SPWeb $WebURL
$List = $Web.Lists[$ListName]

#Get the List Item to update
$ListItem = $List.GetItembyID($ListItemID)

#Update the Yes/No Field Value
$ListItem[$FieldName] = $False
$ListItem.Update()

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!

Leave a Reply

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