Get SharePoint Document Library Size using PowerShell


There was requirement to get the document library size. Using PowerShell I able to resolve this requirement.

This post is about getting actual Document Library size using PowerShell.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
Add-PSSnapin Microsoft.SharePoint.PowerShell 

$siteURL = "YourSitename" 
$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/1KB),2)+"KB"     
}
}
}

I hope this small script will save your time.

Comments

  1. Very nice and effective script. Effective, recommended to few users
    SharePoint development training

    ReplyDelete
  2. Can you please add the commands to export the same output to csv

    ReplyDelete

Post a Comment

Popular posts from this blog

Search Result Webpart,Filter result If QueryString is present in URL

SharePoint 2013 Workflow gets canceled automatically

Permission denied for "Add and Customize Pages" in Sharepoint Online