question

David-5125 avatar image
0 Votes"
David-5125 asked JulieWang-MSFT commented

Add-PnPListItem - List View Threshold

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?


office-sharepoint-onlinesharepoint-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JulieWang-MSFT avatar image
0 Votes"
JulieWang-MSFT answered JulieWang-MSFT commented

@David-5125,

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks Julie.
I am aware of the list view threshold and this is obviously what is causing the issue. I cannot use a different list, and SPO is more than capable of using large lists.

I changed my script to use CSOM instead of PnP. Any clues as to why PnP fails when creating an item in a subfolder, but not the root, would be appreciated.

0 Votes 0 ·

@David-5125,

Is there any progress on this issue?

Please feel free to reply.

0 Votes 0 ·
linyus avatar image
0 Votes"
linyus answered JulieWang-MSFT commented

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.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

That is of course true, however I am adding an item, not retrieving items

0 Votes 0 ·

@David-5125,

How did you get the folder name?If possible, please provide the full code for further troubleshooting.

0 Votes 0 ·