Problem with pnp powershell Get-PnPFolder

IT SUPPORT 1 Reputation point
2021-08-17T07:42:16.503+00:00

Hi ,

I have a problem with Get-PnPFolder when I try to execute this command I get The attempted operation is prohibited because it exceeds the list view threshold error. I know if I use Get-Pnplistitems I can use -PageSize to get around this, but Get-PnPFolder dose not have this option, how can I get past this error?

Any help would be appreciated

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,722 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Echo Du_MSFT 17,116 Reputation points
    2021-08-18T02:02:23.99+00:00

    Hello @IT SUPPORT ,

    You can run the below command to get all folders:

    #Treat the folder as item, and the item attribute is Folder (FileSystemObjectType -eq "Folder")  
    $Folders = Get-PnPListItem -List $List -PageSize 500 -Fields FileLeafRef | Where {$_.FileSystemObjectType -eq "Folder"}  
    

    For example: PnP PowerShell to Get All Folders from a SharePoint Online Document Library

    #Parameters  
    $SiteURL = "https://tenant.sharepoint.com/sites/sitename"  
    $ListName = "libraryname"  
    $CSVPath = "C:\Temp\Folders.csv"  
    $FoldersInventory = @()  
       
    #Connect to Site  
    Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)  
       
    #Get the List  
    $List =  Get-PnPList -Identity $ListName  
       
    #Get all Folders from List - with progress bar  
    $global:counter = 0;  
    $Folders = Get-PnPListItem -List $List -PageSize 500 -Fields FileLeafRef -ScriptBlock { Param($items) $global:counter += $items.Count; Write-Progress -PercentComplete ($global:Counter / ($List.ItemCount) * 100) -Activity "Getting Folders from List:" -Status "Processing Items $global:Counter to $($List.ItemCount)";}  | Where {$_.FileSystemObjectType -eq "Folder"}  
         
    #Iterate through all folders in the list  
    $Folders | ForEach-Object {  
        #Collect Folder data  
        $FoldersInventory += [PSCustomObject] @{  
            FolderName = $_.FieldValues.FileLeafRef  
            URL = $_.FieldValues.FileRef  
        }    
    }  
    $FoldersInventory  
    $FoldersInventory | Export-Csv -Path $CSVPath -NoTypeInformation  
    

    124105-powershell.png

    Thanks,
    Echo Du

    ================================

    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.