title: powershell CSOM get list item ID from ListItems
body: <p>Usually SharePoint lists are updated like so:</p>
  <pre><code>#Get the List    
  $List = $Ctx.Web.Lists.GetByTitle($ListName)
  $Ctx.Load($List)
  $Ctx.ExecuteQuery()
  
  #Get All List items
  $ListItemsCAML = New-Object Microsoft.SharePoint.Client.CamlQuery
  $ListItemsCAML.ViewXml = &quot;&lt;View Scope='RecursiveAll'&gt;&lt;/View&gt;&quot;
  $ListItems = $List.GetItems($ListItemsCAML)
  $Ctx.Load($ListItems)
  $Ctx.ExecuteQuery()
  
  Foreach ($ListItem in $ListItems) {
      #Set New value for List column
      $ListItem[&quot;Reference&quot;] = $ListItem[&quot;ID&quot;]
      $ListItem.Update()
      $Ctx.ExecuteQuery() 
  }
  </code></pre>
  <p>I am trying to update SharePoint list with values from JSON files, therefore I am looping through them, and not through ListItems variable (ListItemCollection). So in case there is no record in the SP list for new JSON, add one. For that, I'd like to skip one loop, and update $ListItems directly:</p>
  <pre><code>ForEach ($json in $json_files) {
    $jsonSONitem = Get-Content $json.FullName | ConvertFrom-Json
  
    # somehow get ID of list item from $ListItems
    # $ID = $ListItems.FieldValues.Where{$_.Name -eq $json.Name}.ID
  
    $ListItems[$ID].FieldValues.Name=&quot;JSONitem.Name
  }
  $ListItem$.Update()
  $Ctx.ExecuteQuery()
  </code></pre>
  <p>However, I am struggling to get ID for child objects of $ListItems. Or maybe I am just trying to use CSOM in a wrong way and I have to loop 'ForEach ($ListItem in $ListItems)' no matter what ?</p>