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

whhtz7ly  于 2023-06-29  发布在  Shell
关注(0)|答案(2)|浏览(114)

我有一个非常大的SharePoint文件夹,其中有许多嵌套的子文件夹,我试图在将该文件夹迁移到其他位置之前计算其中有多少项。
我有这个简单的脚本,但我总是得到这个错误时,每一个我试图计算一个文件夹,真的很大,所以只是想知道我如何才能增加阈值或解决这个问题。

$SiteURL = "https://company-my.sharepoint.com/personal/hello_nam_corp_com"
$searchfor  = "/Documents/Archive"
$folderpath = "Documents/Archive"
$CSVFile = "C:\Users\Desktop\Resource\FolderStats.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
ljo96ir5

ljo96ir51#

试试下面的PowerShell。

#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$ListName = "Branding"
$CSVFile = "C:\Temp\FolderStats.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

myss37ts

myss37ts2#

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

Get-PnPListItem -List Tasks -PageSize 1000

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

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

更多信息:https://pnp.github.io/powershell/cmdlets/Get-PnPListItem.html

相关问题