Add-PnPListItem - List View Threshold

David 41 Reputation points
2021-09-07T17:54:28.487+00:00

I'm trying to load items into an SPO list using PnP.PowerShell.
The list contains about 21k folders at the root; I am trying to create items in the subfolders.

If I call...

Add-PnPListItem -List $list -ContentType $ctname

... it works fine.

But if I try to specify the folder using..

Add-PnPListItem -List $list -ContentType $ctName -Folder $foldername

... I get an error:

PS C:\Users\me\Desktop\> Add-PnPListItem -List $list -ContentType $ctname -Folder $foldername
Add-PnPListItem : The attempted operation is prohibited because it exceeds the list view threshold.
At line:1 char:1

  • Add-PnPListItem -List $list -ContentType $ctname -Folder $foldername...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : WriteError: (:) [Add-PnPListItem], ServerException
  • FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Lists.AddListItem

How can I get PnP to create items in the required subfolder?

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,625 questions
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.
2,668 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. JoyZ 18,041 Reputation points
    2021-09-08T08:39:03.813+00:00

    @David ,

    From the error message, we suggest you switch to another list with less folders(less than 5k), then run commands to compare the result.

    In additon, make sure items in subfolder less than 5000, in SharePoint Online we have a list view threshold limit which is 5000, when we exceed this limit, it will cause some unexpected behaviors and performance issues.


    If an Answer is helpful, please click "Accept Answer" and upvote it.

    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.


  2. Linyu 11 Reputation points MVP
    2021-09-09T07:48:29.363+00:00

    One request can't return more than 5k items, so you should get the items for many times.
    And make sure any request can't be more than 5k items.