Welcome to Q&A Forum!
The way to workaround this is pagination of the view. This means that we will have a row limit of the result that the query can return that should be less or equal to 5000. Once we get the first 5000 items we can do another query for the next 5000 starting from the position where the first result(page) ends.
Below is an example PowerShell snippet that will take all items from a list using 5000 items page size.
#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"
#Config Parameters
$SiteURL="https://xxxx.sharepoint.com/sites/echodu/"
$DocLibName="{YYYY}"
Try {
#Setup Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
$list = $ctx.Web.Lists.GetByTitle($DocLibName)
$ctx.Load($list)
$ctx.ExecuteQuery()
#View XML
$qCommand = @"
<View Scope="RecursiveAll">
<Query>
</Query>
<RowLimit Paged="TRUE">10</RowLimit>
</View>
"@
#Page Position
$position = $null
#All Items
$allItems = @()
Do{
$camlQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
$camlQuery.ListItemCollectionPosition = $position
$camlQuery.ViewXml = $qCommand
#Executing the query
$currentCollection = $list.GetItems($camlQuery)
$ctx.Load($currentCollection)
$ctx.ExecuteQuery()
#Getting the position of the previous page
$position = $currentCollection.ListItemCollectionPosition
#Adding current collection to the allItems collection
$allItems += $currentCollection
ForEach($Item in $allItems)
{
#Do Something
Write-Host "Id :" $Item["ID"]
Write-Host "File Name :" $Item["FileLeafRef"]
Write-Host "File Path :" $Item["FileRef"]
Write-Host "-----------------------------"
}
}
#The position of the last page will be Null
While($position -ne $null)
}
Catch {
write-host -f Red "Error Getting List Items:" $_.Exception.Message
}
Thanks,
Echo Du
===========================================
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.