如何在PowerShell中增加列表视图阈值



我有一个很大的SharePoint文件夹,里面有很多嵌套的子文件夹,在将该文件夹迁移到不同的位置之前,我正在计算其中有多少项。

我有一个简单的脚本,但每次我试图计算一个非常大的文件夹时,我总是会遇到这个错误,所以我想知道如何提高阈值或解决这个问题。

$SiteURL = "https://company-my.sharepoint.com/personal/hello_nam_corp_com"
$searchfor  = "/Documents/Archive"
$folderpath = "Documents/Archive"
$CSVFile = "C:UsersDesktopResourceFolderStats.csv"
#Connect to SharePoint Online
Connect-PnPOnline $SiteURL -useWebLogin

#Get the list
#$documents = Get-PnPList -Identity $ListName | Where-Object {$_.Title -eq 'Documents'}
$FolderItems = Get-PnpListItem -List $folderpath
$fieldvalues = $FolderItems.Fieldvalues
$result = @()
foreach ($field in $fieldvalues) {
$obj = New-object psobject -property $field 
$result += $obj.fileref
}
$final = $result | where-object {$_ -match $searchfor}
$item = New-Object psobject -Property @{
FolderName     = Split-Path -Path $searchfor -Leaf 
URL            = $searchfor 
filesfoldercount = $final.count
}
$item 
$item  |  Export-Csv -Path $CSVFile -NoTypeInformation
Get-PnpListItem : The attempted operation is prohibited because it exceeds the list view threshold.
At line:13 char:16
+ $FolderItems = Get-PnpListItem -List $folderpath

请尝试以下PowerShell。

#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$ListName = "Branding"
$CSVFile = "C:TempFolderStats.csv"

#Connect to SharePoint Online
Connect-PnPOnline $SiteURL -Interactive

#Get the list
$List = Get-PnPList -Identity $ListName

#Get Folders from the Library - with progress bar
$global:counter = 0
$FolderItems = Get-PnPListItem -List $ListName -PageSize 500 -Fields FileLeafRef -ScriptBlock { Param($items) $global:counter += $items.Count; Write-Progress -PercentComplete `
($global:Counter / ($List.ItemCount) * 100) -Activity "Getting Items from List:" -Status "Processing Items $global:Counter to $($List.ItemCount)";}  | Where {$_.FileSystemObjectType -eq "Folder"}
Write-Progress -Activity "Completed Retrieving Folders from List $ListName" -Completed

$FolderStats = @()
#Get Files and Subfolders count on each folder in the library
ForEach($FolderItem in $FolderItems)
{
#Get Files and Folders of the Folder
Get-PnPProperty -ClientObject $FolderItem.Folder -Property Files, Folders | Out-Null

#Collect data
$Data = [PSCustomObject][ordered]@{
FolderName     = $FolderItem.FieldValues.FileLeafRef
URL            = $FolderItem.FieldValues.FileRef
FilesCount     = $FolderItem.Folder.Files.Count
SubFolderCount = $FolderItem.Folder.Folders.Count
}
$Data
$FolderStats+= $Data
}
#Export the data to CSV
$FolderStats | Export-Csv -Path $CSVFile -NoTypeInformation

脚本链接:https://www.sharepointdiary.com/2019/05/sharepoint-online-get-files-sub-folders-count-in-document-library-using-powershell.html

帮助您有点晚了,但仍然值得一提的是,您可以添加PageSize参数以在指定大小的页面中返回结果:

Get-PnPListItem -List Tasks -PageSize 1000

在您的示例中,您可以在此处添加以下内容:

$FolderItems = Get-PnpListItem -List $folderpath -PageSize 1000

更多信息请点击此处:https://pnp.github.io/powershell/cmdlets/Get-PnPListItem.html

相关内容

  • 没有找到相关文章

最新更新