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
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:
Here is my other PowerShell scripts to get data from list items in SharePoint Online:
SharePoint Online PowerShell to Get List Item Field Value
#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]
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 is my other PowerShell scripts to get data from list items in SharePoint Online:
No comments:
Please Login and comment to get your questions answered!