kwizcom banner advertisement

SharePoint Online: Get-Set "Yes/No (Check box)" Field Value using PowerShell

Requirement: Get or Set Yes/No Field Value in SharePoint Online using PowerShell.

PowerShell to Get Value of Yes/No Field in SharePoint Online:
Here is how you can read Yes/No field programmatically using PowerShell.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#Set parameter values accordingly
$SiteURL="https://crescent.sharepoint.com/"
$ListName="Projects"
$FieldName="IsActive" #Internal Name
$ListItemID="5"
 
#Get Credentials to connect
$Cred= Get-Credential
  
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
#Get the List Item
$List = $Ctx.Web.lists.GetByTitle($ListName)
$ListItem = $List.GetItemById($ListItemID)
$Ctx.Load($ListItem)
$Ctx.ExecuteQuery()

#Get the Yes/No Field Value
$ListItem[$FieldName]

Update Yes/No Field value in SharePoint Online List using PowerShell
Lets update Yes/No field in SharePoint online list programmatically
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#Set parameter values
$SiteURL="https://crescent.sharepoint.com/"
$ListName="Projects"
$FieldName="IsActive" #Internal Name
$ListItemID="5"
 
#Get Credentials to connect
$Cred= Get-Credential
  
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
#Get the List Item
$List = $Ctx.Web.lists.GetByTitle($ListName)
$ListItem = $List.GetItemById($ListItemID)
$Ctx.Load($ListItem)
$Ctx.ExecuteQuery()

#Update the Yes/No Field Value
$ListItem[$FieldName] = $True
$ListItem.update()
$Ctx.ExecuteQuery()

Write-host -f Green "Field Value Updated!"
SharePoint Online: Get-Set "Yes/No (Check box)" Field Value using PowerShell SharePoint Online: Get-Set "Yes/No (Check box)" Field Value using PowerShell Reviewed by Salaudeen Rajack on April 30, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.