The attempted operation is prohibited because it exceeds the list view threshold

Imran Shabir 21 Reputation points
2023-08-14T14:06:27.9833333+00:00

Hi, I am trying to create a bulk folder list to a Shared Documents/subfolder1 on Sharepoint Online but i keep getting the threshold error. There were 3790 already there with files inside them and i did attempt to upload 4993 new folders but it started giving the threshold error with 115 folders remaining. What i have tried is a few different scripts and upgrading Powershell to v7 but it fails to create new folders within 1 subfolder of Shared Documents.

Error:error2

the script i am using is:

#Config Variables
$SiteURL = "https://tenant.sharepoint.com/sites/sitename" 
$CSVFilePath = "C:\Script\NewFoldersfile.csv"
$LibraryName = "Shared Documents"


Try  {
     #Connect to PnP Online
     Connect-PnPOnline -Url $SiteURL
	 $Web = Get-PnPWeb

     #Get the Document Library and its site relative URL
     $Library = Get-PnPList -Identity $LibraryName #-Includes RootFolder
     If($Web.ServerRelativeUrl -eq "/")
     {
         $LibrarySiteRelativeURL = $Library.RootFolder.ServerRelativeUrl
     }
     else
     {
         $LibrarySiteRelativeURL = $Library.RootFolder.ServerRelativeUrl.Replace($Web.ServerRelativeUrl,'')
     }

     #Get the CSV file
     $CSVFile = Import-Csv $CSVFilePath
     #Read CSV file and create folders
     ForEach($Row in $CSVFile)
     {
         # This part checks for the folder name and confirm it doesnt have Invalid Characters
         $FolderName = $Row.FolderName
         # Invalid characters example on $FolderName = [RegEx]::Replace($FolderName, "[{0}]" -f ([RegEx]::Escape([String]'\"*:<>?/\|')), '_')
         #Frame the Folder Name 
         $FolderURL = $LibrarySiteRelativeURL+"/"+$FolderName

         #Create Folder if it doesn't exist
         Resolve-PnPFolder -SiteRelativePath $FolderURL | Out-Null
         Write-host "Folder Created:"$FolderName -f Green
     }
 }
catch
{
     write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,230 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,628 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,906 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Rich Matheisen 47,856 Reputation points
    2023-08-14T15:02:24.4433333+00:00

  2. RaytheonXie_MSFT 40,426 Reputation points Microsoft External Staff
    2023-08-15T02:53:08.1233333+00:00

    Hi @Imran Shabir,

    It's well know SharePoint has a 5000 Document Library limit. So for large number of folders and files upload, I will recommend you to use SharePoint Migration tool.

    It accepts a CSV input on a map between folders and different sites/document libraries/subfolders. It will allow you to go back and check for changes after the initial run, and you can keep re-running it.

    Here is the document for more details

    Overview of the SharePoint Migration Tool (SPMT)


    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.


  3. Imran Shabir 21 Reputation points
    2023-08-17T07:36:07.4966667+00:00

    Hi, would a filter query work on this?


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.