Búsqueda de sitios web

SharePoint Online: buscar todas las carpetas que superen el límite de umbral de vista de lista de 5000


Problema: Cualquier lista, biblioteca o carpeta de SharePoint contiene más de 5000 elementos en el mismo nivel, el umbral de vista de lista de resultados superó los mensajes de error en SharePoint Online. Si bien la cantidad máxima de elementos o archivos que se pueden almacenar en la lista o biblioteca de SharePoint Online es 30 millones, no se pueden almacenar más de 5000 elementos en el mismo nivel. ¡Deben clasificarse en subcarpetas! Si no,

  • Cuando intentas abrir en la vista "Explorador de archivos", verás el mensaje "Esta carpeta está vacía", aunque la carpeta tiene contenido.
  • Si intenta navegar a estos contenedores utilizando el diseñador de SharePoint, obtendrá "Error del servidor: el intento de operación está prohibido porque excede el umbral de vista de lista impuesto por el administrador".

  • Si explora estas bibliotecas o carpetas, recibirá uno de los siguientes mensajes de error “Algo salió mal. Inténtalo de nuevo o actualiza la página”.

Entonces, para evitar problemas del usuario final de manera proactiva, queríamos encontrar todas las carpetas (incluida la carpeta raíz de una lista o biblioteca y subcarpetas) con 5000 elementos en ellas.

PowerShell para buscar todas las carpetas que contienen más de 5000 elementos en SharePoint Online:

Este script de PowerShell escanea la colección de sitios dada en busca de carpetas con > 5000 elementos almacenados en el mismo nivel.


#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Funds"
$ListviewThreshold = 5000
$CSVPath = "C:\Temp\ListviewThreshold.csv"
$Global:ListviewInventory = @()
$Pagesize = 2000
 
#Function to audit list view threshold
Function Audit-ListviewThreshold
{
[cmdletbinding()]
 
    param([parameter(Mandatory = $true, ValueFromPipeline = $true)] $Web)
  
    Write-host "Scanning Large Lists on Site '$($Web.URL)'"
      
    #Get All Large Lists from the Web - Exclude Hidden and certain lists
    $ExcludedLists = @("Form Templates", "Preservation Hold Library","Site Assets", "Pages", "Site Pages", "Images",
                            "Site Collection Documents", "Site Collection Images","Style Library")
    $Lists= Get-PnPProperty -ClientObject $Web -Property Lists        
    $LargeLists = $Lists | Where-Object {$_.Hidden -eq $False -and $_.Title -notin $ExcludedLists -and $_.ItemCount -gt $ListviewThreshold}
     
    #Process all large lists
    $LargeLists | ForEach-Object {        
        $Folder = Get-PnPProperty -ClientObject $_ -Property RootFolder
        Write-host "`tAuditing Items at List '$($Folder.ServerRelativeUrl)'" -f Yellow
        #Check the Root Folder
        If($Folder.ItemCount -gt $ListviewThreshold)
        {
            Write-host "`t`tFound a Folder with '$($Folder.ItemCount)' Items at '$($Folder.ServerRelativeURL)'" -f Green
            #Collect data
            $global:ListviewInventory += New-Object PSObject -Property ([ordered]@{
                SiteURL  = $Web.URL
                FolderName = $Folder.Name
                URL = $Folder.ServerRelativeUrl
                ItemCount = $Folder.ItemCount
            })
        }
        #Get Folders from List       
        $global:counter = 0;
        $LargeFolders = Get-PnPListItem -List $_ -PageSize $Pagesize -Fields ItemChildCount,FolderChildCount -ScriptBlock { Param($items) $global:counter += $items.Count; Write-Progress -PercentComplete ($global:Counter / ($_.ItemCount) * 100) -Activity "Getting List Items of '$($_.Title)'" -Status "Processing Items $global:Counter to $($_.ItemCount)";}  | Where {$_.FileSystemObjectType -eq "Folder"}
  
        #Process all large folders in the list
        $LargeFolders | ForEach-Object {
            #Get the Item count in Folder
            $ItemsCount = [int]$_.FieldValues.ItemChildCount
            $SubfoldersCount = [int]$_.FieldValues.FolderChildCount
            $ItemCount = $ItemsCount + $SubfoldersCount
 
            If($ItemCount -gt $ListviewThreshold)
            {
                Write-host "`t`tFound a Folder with '$ItemCount' Items at '$($_.FieldValues.FileRef)'" -f Green
                #Collect data
                $global:ListviewInventory += New-Object PSObject -Property ([ordered]@{
                    SiteURL  = $Web.URL
                    FolderName = $_.FieldValues.FileLeafRef
                    URL = $_.FieldValues.FileRef
                    ItemCount = $ItemCount
                })
            }
        }
    }
}
 
#Connect to Site collection
Connect-PnPOnline -Url $SiteURL -Interactive  
 
#Iterate through all webs in the site collections and call the function
Get-PnPSubWeb -Recurse -IncludeRootWeb | ForEach-Object { Audit-ListviewThreshold $_ }

#Export Documents Inventory to CSV
$Global:ListviewInventory | Export-Csv $CSVPath -NoTypeInformation

Auditar el recuento de elementos de la carpeta a nivel de inquilino mediante PnP PowerShell:

Esta vez, auditemos todas las carpetas de las colecciones de sitios en todo el inquilino.


#Parameters
$Domain =  "CrescentIntranet" #Domain Name in SharePoint Online. E.g. https://Crescent.sharepoint.com
$ListviewThreshold = 4000
$CSVPath = "C:\Temp\ListviewThreshold.csv"
$Global:ListviewInventory = @()
$Pagesize = 2000

#Frame Tenant URL and Tenant Admin URL
$TenantURL = "https://$Domain.SharePoint.com"
$TenantAdminURL = "https://$Domain-Admin.SharePoint.com"

#Function to audit list view threshold
Function Audit-ListviewThreshold
{
[cmdletbinding()]

    param([parameter(Mandatory = $true, ValueFromPipeline = $true)] $Web)
 
    Write-host "Scanning Large Lists on Site '$($Web.URL)'"
     
    #Get All Large Lists from the Web - Exclude Hidden and certain lists
    $ExcludedLists = @("Form Templates", "Preservation Hold Library","Site Assets", "Pages", "Site Pages", "Images",
                            "Site Collection Documents", "Site Collection Images","Style Library")
    $Lists= Get-PnPProperty -ClientObject $Web -Property Lists     
    $LargeLists = $Lists | Where-Object {$_.Hidden -eq $False -and $_.Title -notin $ExcludedLists -and $_.ItemCount -gt $ListviewThreshold}
    
    #Process all large lists
    $LargeLists | ForEach-Object {        
        $Folder = Get-PnPProperty -ClientObject $_ -Property RootFolder
        Write-host "`tAuditing Items at List '$($Folder.ServerRelativeUrl)'" -f Yellow
        #Check the Root Folder
        If($Folder.ItemCount -gt $ListviewThreshold)
        {
            Write-host "`t`tFound a Folder with '$($Folder.ItemCount)' Items at '$($Folder.ServerRelativeURL)'" -f Green
            #Collect data
            $global:ListviewInventory += New-Object PSObject -Property ([ordered]@{
                SiteURL  = $Web.URL
                FolderName = $Folder.Name
                URL = $Folder.ServerRelativeUrl
                ItemCount = $Folder.ItemCount
            })
        }
        #Get Folders from List       
        $global:counter = 0;
        $LargeFolders = Get-PnPListItem -List $_ -PageSize $Pagesize -Fields ItemChildCount,FolderChildCount -ScriptBlock { Param($items) $global:counter += $items.Count; Write-Progress -PercentComplete ($global:Counter / ($_.ItemCount) * 100) -Activity "Getting List Items of '$($_.Title)'" -Status "Processing Items $global:Counter to $($_.ItemCount)";}  | Where {$_.FileSystemObjectType -eq "Folder"}
        Write-Progress -Activity "Completed Retrieving Items from List $($Folder.ServerRelativeUrl)" -Completed

        #Process all large folders in the list
        $LargeFolders | ForEach-Object {
            #Get the Item count in Folder
            $ItemsCount = [int]$_.FieldValues.ItemChildCount
            $SubfoldersCount = [int]$_.FieldValues.FolderChildCount
            $ItemCount = $ItemsCount + $SubfoldersCount

            If($ItemCount -gt $ListviewThreshold)
            {
                Write-host "`t`tFound a Folder with '$ItemCount' Items at '$($_.FieldValues.FileRef)'" -f Green
                #Collect data
                $global:ListviewInventory += New-Object PSObject -Property ([ordered]@{
                    SiteURL  = $Web.URL
                    FolderName = $_.FieldValues.FileLeafRef
                    URL = $_.FieldValues.FileRef
                    ItemCount = $ItemCount
                })
            }
        }
    }
}

#Connect to Admin Center
Connect-PnPOnline -Url $TenantAdminURL -Interactive
   
#Get All Site collections - Filter BOT and MySite Host
$Sites = Get-PnPTenantSite -Filter "Url -like '$TenantURL'"
  
#Iterate through all site collections
$Sites | ForEach-Object {
    #Connect to each site collection
    Connect-PnPOnline -Url $_.URL -Interactive
  
    #Iterate through all webs in the site collections and call the function
    Get-PnPSubWeb -Recurse -IncludeRootWeb | ForEach-Object { Audit-ListviewThreshold $_ }
}
 
#Export Documents Inventory to CSV
$Global:ListviewInventory | Export-Csv $CSVPath -NoTypeInformation

Mi publicación relacionada sobre el umbral de vista de lista en SharePoint Online: preguntas frecuentes

Artículos relacionados