1

I'm facing an issue when trying to use PowerShell to get information on document library sizes in site collections with SharePoint 2013 on-prem.

My PowerShell code is as follows:

$siteURL = "http://myonpremsharepoint.com/sites/ABC"
$site = new-object Microsoft.SharePoint.SPSite($siteURL)

foreach ($web in $site.AllWebs)
{
  foreach ($list in $web.Lists)
  {
    if($list.BaseType -eq "DocumentLibrary")  
      {
        $listSize = 0
        foreach ($item in $list.items)
        {
          $listSize += ($item.file).length
        }
      "Web: "+$web.Title+", Library Name: "+$list.Title+", Size: "+[Math]::Round(($listSize/1KB),2)+"KB"    
    }
  }
}

The error I receive after running on this on some of my larger document libraries is as follows:

The following exception occurred while trying to enumerate the collection: "The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator"

At Line: 8 char:22
  foreach ($item in $list.items)
  CategoryInfo                  : NotSpecified: <:> [], ExtendedTypeSystemException
  FullyQualifiedErrorId : ExceptionInGetEnumerator

Is there a way to rewrite the above PowerShell query to ignore this limitation without having to specifically change the threshold limit for the given document library?

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.