title: How do I retrieve all items from a Sharepoint list using CSOM if I can only retrieve N items as a time?
body: <p>I'm writing a Powershell script to retrieve all items from a list. I've been told by my superiors that I'm limited to pulling 200 rows at a time, so I wrote the following code with that in mind:</p>
  
  <pre><code>function getLookupValues($_ctx, $_listName, $_colToMatch)
  {
      $lookupList = $_ctx.Web.Lists.GetByTitle($_listName)
      $query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery(200, 'ID', $_colToMatch)
      $vals = $lookupList.getItems($query)
      $_ctx.Load($lookupList)
      $_ctx.Load($vals)
      $_ctx.ExecuteQuery()
  
      return $vals
  }
  </code></pre>
  
  <p>The list I'm testing has over 200 items in it. When I run this code, I retrieve only the first 200 items. I suppose that's as expected, but I figured since the query is called an "All Items" query, it might know to repeatedly query for 200 items until it reaches the end of the list. However, as I found out through testing, that isn't the case.</p>
  
  <p>What's the proper way to retrieve every item in a list if I'm given a limit of N rows per query? Do I need to perform some kind of loop that repeatedly queries and dumps the results into a holding array until all of the items have been retrieved?</p>