Get-PnPFolderItem is always returning "The attempted operation is prohibited because it exceeds the list view threshold."

gokulnath palani 0 Reputation points
2024-12-26T11:35:20.65+00:00

I have the following script to get files in particular folder (we have 5.5 K).

User's image

But it will raise this exception:-

Get-PnPFolderItem : The attempted operation is prohibited because it exceeds the list view threshold. At line:1 char:10

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,214 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Emily Du-MSFT 49,001 Reputation points Microsoft Vendor
    2024-12-27T03:00:26.7633333+00:00

    Please follow below tips to troubleshoot the issue.

    1.Get items by paging to avoid returning more than 5000 items at a time. Use $batchSize parament in the PNP PowerShell.

    $batchSize = 1000
    $items = @()
    $batch = Get-PnPListItem -List "YourListName" -PageSize $batchSize
    while ($batch -ne $null) {
    $items += $batch
    $batch = $batch.Skip($batchSize).Take($batchSize)
    }
    

    2.Create indexed columns in the document library.

    Go to SharePoint library settings -> In the Columns section, click Indexed columns -> Create a new index.


    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.