SharePoint Online: PowerShell to Get List Item Field Value

Requirement: PowerShell to Get List Item Field Value in SharePoint Online.

SharePoint Online PowerShell to Get List Item Field Value

As a SharePoint Online administrator, there will be times when you need to get the field value of a list item through PowerShell. In this blog post, I’ll show you how to use PowerShell to get the field value of a list item.

#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"
  
#Parameters
$SiteURL = "https://crescenttech.sharepoint.com"
$ListName = "Projects"
$FieldName = "Manager"
$ItemId="1"

#Set Authentication Parameters
$UserName = "[email protected]"
$Password = "Password1"
$SecurePassword= $Password | ConvertTo-SecureString -AsPlainText -Force

#Setup the Context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
 
#Get List Item
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$ListItem = $List.GetItemById($ItemId)
$Ctx.Load($ListItem)
$Ctx.ExecuteQuery()    

#Get the Field Value
$ListItem[$FieldName]

#Also does the same: Get the Field Value
#$ListItem.FieldValues[$FieldName]

The above script returns data as per the field type. E.g. as the “Manager” field is “Person or Lookup”, this PowerShell script returns Microsoft.SharePoint.Client.FieldUserValue data type. Let’s get only the text value from a field as:

#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"
  
#Parameters
$SiteURL = "https://crescenttech.sharepoint.com"
$ListName = "Projects"
$FieldName = "Manager"
$ItemId="1"

#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 List Item
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$ListItem = $List.GetItemById($ItemId)
$Ctx.Load($ListItem)
$Ctx.ExecuteQuery()

#Get List Item Field Values as Text
$ListItemFieldValues = $ListItem.FieldValuesAsText
$Ctx.Load($ListItemFieldValues)
$Ctx.ExecuteQuery()

#Get the Text value of "Manager" field from the list Item
$ListItemFieldValues[$FieldName]

Here are my other PowerShell scripts to get data from list items in SharePoint Online:

  1. SharePoint Online: Get Yes/No Checkbox Field Value using PowerShell
  2. SharePoint Online: Get Lookup Field Value using PowerShell
  3. SharePoint Online: Get Person or group Field Value using PowerShell

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!

Leave a Reply