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.
Update Yes/No Field value in SharePoint Online List using PowerShell
Lets update Yes/No field in SharePoint online list programmatically.
PnP PowerShell to Update "Yes/No" Field Values in SharePoint Online
To set the value for "Yes/No" boolean fields, use Values @{"YesNoFieldInternalName" = $True/$false}. Here is an example:
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!"
PnP PowerShell to Update "Yes/No" Field Values in SharePoint Online
To set the value for "Yes/No" boolean fields, use Values @{"YesNoFieldInternalName" = $True/$false}. Here is an example:
#Config Variables $SiteURL = "https://crescent.sharepoint.com/sites/pmo" $ListName = "Projects" $FieldName = "IsActive" $ItemID = 1 #Connect to PnP Online Connect-PnPOnline -Url $SiteURL -UseWebLogin #Update Yes/No Field Value Set-PnPListItem -List $ListName -Identity $ItemID -Values @{$FieldName = $True}
No comments:
Please Login and comment to get your questions answered!