Moving a large folder using Move-PnPFolder throws threshold exception
Reporting an Issue or Missing Feature
I'm trying to move a large folder in SharePoint Online which has many subfolders with thousands of items from one library to another using the cmdlet Move-PnPFolder. It throws the exception "The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator". For relatively small folders with around 2000 items the cmdlet times out leaving the move operation in inconsistent state.
Is there a way to bulk copy files in SharePoint online? I tried to recursively iterate through source folders using the Get-PnPFolderItem, create folder in destination and copy one file at a time to the target location using the Copy-PnPFile command. However the operation is very slow and also in between I get timeout errors, remote server etc.
Expected behavior
Expect the folder to be moved with no errors
Actual behavior
Exception "The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator". For relatively small folders with around 2000 items the cmdlet times out leaving the move operation in inconsistent state.
Steps to reproduce behavior
Which version of the PnP-PowerShell Cmdlets are you using?
- [ ] PnP PowerShell for SharePoint Online
What is the version of the Cmdlet module you are running?
3.14.1910.1
How did you install the PnP-PowerShell Cmdlets?
- [ ] Installed through the PowerShell Gallery with Install-Module
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
I'm also getting an error when moving large folders but it isn't a threshold exception
Move-PnPFolder : The underlying connection was closed: An unexpected error occurred on a receive.
Just hoping to resurrect this one if possible. We are attempting to copy items between folders and it worked great until the list hit the 5000 item threshold. Only workaround we've found so far is performing a three-stage process where we copy the items to a local folder, delete them from the online folder, and then upload the local copies to the new folder.
@etherjack I have solved this with a script to get all subfolders in a folder and loop them with a foreach script:
In this script I move the files to a new document library within the same site:
#Set Variables
$SiteURL = "https://123456asdf.sharepoint.com/sites/Finance/"
$FolderURL = "Shared Documents"
$TargetFolderURL = "Archive 2015"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Get all Sub-Folders of folder
Function Get-SubFolders($FolderURL)
{
#Get all sub-folders of the Folder
$SubFolders = Get-PnPFolderItem -FolderSiteRelativeUrl $FolderURL -ItemType Folder | Where {$_.Name -ne "Forms" -and $_.Name -ne "Document"}
#Loop through the folders
ForEach($SubFolder in $SubFolders)
{
$SourceFolderURL = $FolderUrl+"/"+$SubFolder.Name
Move-PnPFolder -Folder $SourceFolderURL -TargetFolder $TargetFolderURL
}
}
#Call the function with the root folder of the doc library
Get-SubFolders $FolderURL
The only downside; I do get an error with huge folders;
Move-PnPFolder : The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
It looks like all the files are moved anyway.