Reputation: 19
var camlQuery = new CamlQuery
{
ViewXml = "<View Scope='RecursiveAll'><RowLimit>"+chunkSize+"</RowLimit></View>"
};
context.Load(list, x => x.ItemCount);
context.Load(list, x => x.Title);
var fetchedCount = 0L;
var uniqueRolesCount = 0L;
do
{
camlQuery.FolderServerRelativeUrl = FolderServerRelativeUrl;
var targetItems = list.GetItems(camlQuery);
context.Load(targetItems);
context.Load(targetItems, x => x.Include(y => y.HasUniqueRoleAssignments));
context.ExecuteQuery();
I have use folderServerRelativeUrl in CamlQuery to retrive all list items and getting Threshold Exceeded Error.
Upvotes: 0
Views: 357
Reputation: 372
According to my research and testing, you can use the following code to get list items in SharePoint Online List without List view threshold exceeded Error:
#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://Crescent.SharePoint.com"
$ListName="Projects"
$BatchSize= 2000
Try {
$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
#Get the List
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$Ctx.Load($List)
$Ctx.ExecuteQuery()
#Define Query to get List Items in batch
$Query = New-Object Microsoft.SharePoint.Client.CamlQuery
$Query.ViewXml = "<View Scope='RecursiveAll'><RowLimit>$BatchSize</RowLimit></View>"
#Get List Items in Batch
Do
{
$ListItems = $List.GetItems($Query)
$Ctx.Load($ListItems)
$Ctx.ExecuteQuery()
$ListItems.count
$Query.ListItemCollectionPosition = $ListItems.ListItemCollectionPosition
}
While($Query.ListItemCollectionPosition -ne $null)
}
Catch {
write-host -f Red "Error Getting List Items:" $_.Exception.Message
}
More information for reference: SharePoint Online: Get List Items from Large Lists ( >5000 Items) using PowerShell without List View Threshold Exceeded Error
Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.
Upvotes: 0