How to get Field values of a list item using CSOM Powershell?

I am using below code:

foreach($field in $List.Fields)
    write-host $field

I am getting the values as output:


But I want all field values like ID, Title, Created By etc.

  • You need to get the fields first so: $fields = $List.Fields; $ctx.load($fields); $ctx.ExecuteQuery() – Bunzab Nov 30 '18 at 9:19
  • @Bunzab Yes i have loaded the fields in my code. I just want the Created By and Modified By values of all the items using CSOM – Adarsh Awasthi Nov 30 '18 at 9:55
  • In that case you need to get each item... – Bunzab Nov 30 '18 at 10:00
  • i am trying to get each item only but it is returning values as Microsoft.SharePoint.Client.FieldLookup instead of user names – Adarsh Awasthi Nov 30 '18 at 10:12
  • $ListItem["Editor"].LookupValue solved my problem – Adarsh Awasthi Dec 3 '18 at 5:48

Your code does not retrieve any list items. This is an example of how you do it:

$listItems = $list.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())

foreach($listItem in $listItems)
    Write-Host "ID - " $listItem["ID"] "Title - " $listItem["Title"]

Credits to: https://www.c-sharpcorner.com/article/list-item-operations-using-csom-with-powershell-for-sharepoi/

|improve this answer|||||
  • $ListItemsCollection =$List.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()) $ctx.load($ListItemsCollection) $ctx.executeQuery() foreach($ListItem in $ListItemsCollection) { $Author = $ListItem["Author"].LookupValue Write-Host $Author $Editor = $ListItem["Editor"].LookupValue Write-Host Editor } – Adarsh Awasthi Dec 3 '18 at 5:44
  • Thanks @Denis. I was actually looking for $ListItem["Editor"].LookupValue which gives the values of user names instead of their types. – Adarsh Awasthi Dec 3 '18 at 5:47

You need to get the item/s first (either by CAML query or by id) and the property values are accessible via:


So you can get the values you are after like so:

|improve this answer|||||

If you want to get list item values, you can use this

$web=Get-SPWeb "http://www.myspapp/sites/myspweb"

foreach($item in $list.Items)
    Write-Host  $item["ID"] $item["Title"]

If you want to get column names only, you can use this

$web=Get-SPWeb "http://www.myspapp/sites/myspweb"

foreach($field in $list.Fields)
    Write-Host $field
|improve this answer|||||
  • 2
    I am doing that in CSOM. The above code is for SSOM . Please assist – Adarsh Awasthi Nov 30 '18 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.