Get SharePoint document library size using PowerShell

This PowerShell SharePoint tutorial, we will discuss how to get SharePoint document library size using PowerShell in SharePoint 2013/2016.

Here we will see how to retrieve document library size from a particular site collection using PowerShell as well as we will get document library size from all the subsites from a site collection using PowerShell.

Get SharePoint document library size using PowerShell

Below is the PowerShell script to get document library size using PowerShell in SharePoint 2013/2016. You can run the PowerShell script using PowerShell ISE or Visual Studio Code.

$siteURL = "http://mypc/sites/MySP2016SiteCollection/" 
$site = new-object Microsoft.SharePoint.SPSite($siteURL)
$web=$site.openweb()
 foreach ($list in $web.Lists)
{
      if($list.BaseType -eq "DocumentLibrary")   
      {
        $listSize = 0
        foreach ($item in $list.items) 
        { 
          $listSize += ($item.file).length
        }
        "Web Name: "+$web.Title+", Library Name: "+$list.Title+", Size: "+[Math]::Round(($listSize/1MB),2)+"MB"
}
}

Get document library size using PowerShell from SharePoint subsites

Now, we will see how to get document library size using PowerShell from site collection and subsites in SharePoint 2013/2016.

Here, I am providing a site collection URL and it will display all the document library size from all the sites and subsites in SharePoint.

$siteURL = "http://mypc/sites/MySP2016SiteCollection/" 
$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 Name: "+$web.Title+", Library Name: "+$list.Title+", Size: "+[Math]::Round(($listSize/1MB),2)+"MB"
        }
    }
}

You can run the PowerShell script and can see the output like below:

Get SharePoint document library size using PowerShell

You may like following PowerShell SharePoint tutorials:

See also  SharePoint Column Validation [10 real examples]

This SharePoint tutorial we learned how to get document library size using PowerShell in SharePoint 2013/2016.

>