当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:查找超过列表视图阈值限制 5000 的所有文件夹

作者:精品下载站 日期:2024-12-14 15:36:07 浏览:14 分类:玩电脑

SharePoint Online:查找超过列表视图阈值限制 5000 的所有文件夹


问题:任何 SharePoint 列表、库或文件夹包含超过 5000 个同一级别的项目,结果列表视图阈值超出 SharePoint Online 中的错误消息。虽然 SharePoint Online 列表或库中可以存储的项目或文件的最大数量为 3000 万个,但同一级别不能存储超过 5000 个项目。它们必须分类到子文件夹中!如果不,

  • 当您尝试在“文件资源管理器”视图中打开时,您会看到“此文件夹为空”消息,尽管该文件夹中有内容。
  • 如果您尝试使用 SharePoint 设计器导航到这些容器,您将收到“服务器错误:尝试的操作被禁止,因为它超出了管理员强制执行的列表视图阈值。”

    [玩转系统] SharePoint Online:查找超过列表视图阈值限制 5000 的所有文件夹

  • 如果您浏览这些库或文件夹,您将收到以下错误消息之一“出现问题。请重试或刷新页面”。

[玩转系统] SharePoint Online:查找超过列表视图阈值限制 5000 的所有文件夹

因此,为了主动避免最终用户问题,我们希望找到包含 5000 个项目的所有文件夹(包括列表或库的根文件夹和子文件夹)。

PowerShell 查找 SharePoint Online 中包含超过 5000 个项目的所有文件夹:

此 PowerShell 脚本扫描给定网站集,以查找在同一级别存储了超过 5000 个项目的文件夹。


#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

使用 PnP PowerShell 在租户级别审核文件夹项目计数:

这次,让我们审核整个租户中网站集中的所有文件夹。


#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

我有关 SharePoint Online 中的列表视图阈值的相关帖子 - 常见问题解答

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯