Tuesday 5 May 2015

How to get document library size using PowerShell?

Below is the PowerShell script which will show the size of Particular library:

   [System.reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
    [System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0,             Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
    [System.Reflection.Assembly]::Load(“Microsoft.SharePoint.Portal, Version=12.0.0.0,   Culture=neutral, PublicKeyToken=71e9bce111e9429c”)


    Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

    $siteURL = "YourSiteURL" 
    $site = new-object Microsoft.SharePoint.SPSite($siteURL)


    foreach ($web in $site.AllWebs)
    {
     foreach ($list in $web.Lists)
    {

            if($list.BaseType -eq "DocumentLibrary")   
          {

if($list.Title -eq "YourDocumentLibraryTitle")
{
        $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"     
}
    }
    }
    }


Hope this helps!!!!

1 comment:

Related Posts Plugin for WordPress, Blogger...