none
SP Online ClientContext.Load syntax for specific fields only RRS feed

  • Question

  • What is the correct syntax in the PowerShell CSOM for SharePoint Online to retrieve only a few columns from a list instead of all columns ? I only need to fetch the columns in the write-host statement. The => syntax that is found in many code examples does not seem to work in the online CSOM.

    $poslist = $web.Lists.GetByTitle("Points of Sale")
    $ctx.Load($poslist)
    $ctx.ExecuteQuery()
    
    $caml = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()
    $items = $poslist.GetItems($caml)
    $ctx.Load($items)
    $ctx.ExecuteQuery()
    
    foreach ($item in $items)
    {
        Write-host $item["Title"] $item["Brand"] $item["Name"] $item["Contact"].LookupValue
    }


    Stephane


    • Edited by S Bouillon Tuesday, March 14, 2017 5:19 PM
    Tuesday, March 14, 2017 5:17 PM

All replies

  • Hi Bouillon,

    Did you try like this:

    Load-CSOMProperties -parentObject $web -collectionObject $web.Lists -propertyNames @("Id", "Title") -parentPropertyName "Lists"

    https://www.itunity.com/article/completing-basic-operations-sharepoint-csom-api-powershell-1278

    Thanks 

    Lalith

    --------------------------------------------------------------------------------------------

    Please mark as answer, if my solution helps you.

    Tuesday, March 14, 2017 6:43 PM
  • Thanks for your time and effort,

    The article points to a function that is really a helper function, see http://stackoverflow.com/questions/34336300/how-do-i-do-a-lambda-expression-in-PowerShell for the full code.

    What I was wondering is if there is a standard way of doing this in the SharePoint online csom syntax itself. There seems to be very little documentation on this.


    Stephane

    Tuesday, March 14, 2017 9:07 PM
  • Please mark as answer as it will helps to others also.
    Tuesday, March 14, 2017 9:15 PM
  • I don't mind to mark as answer, but my question was not answered.

    Stephane

    Wednesday, March 15, 2017 9:58 AM