9

How to know exact document library size. any PowerShell code required?

I used

http://XYZ:4444/_layouts/15/storman.aspx

but it doesn't show true size.

I have Just Modified Nikhil's 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 = "Sitename" 
    $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"     
}
    }
    }
    }
11

The code loops through entire site and gives the size of all document libraries.

[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 = "Sitename" 
$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"     
}
}
}

Please reiterate the code at the end . if you want to dispose the objects .

if ($rootWeb -ne $null)
{
    $rootWeb.Dispose()

} 
If ($site -ne $null)
{
    $site.Dispose();
}
  • i had this code in c#.i will test it tomorrow.thanks – SharePointMan Mar 12 '14 at 16:30
  • how much time it will take to count the size say above 100GB? because it is iterating through each item of the folder – SharePointMan Mar 14 '14 at 10:48
  • I used similar code before on similar sized site collections (I was iterating the whole site collection) and I think you need to expect about 30 - 45 mins. – Cameron Verhelst Mar 14 '14 at 13:23
6

I created this simple PowerShell script to calculate for a single Document Library what the size in MB is for all the files inside:

$total = $null; ((get-spweb http://WebApplication/SiteCollection/subsite/).lists | Where-Object {$_.title -eq "Library Title"}).items | foreach {$total+= $_.file.length}; $total /1MB

Before you can use the script you need to know 2 parameters (and replace them in the script):

  • the URL of the site where the document library is located
  • the document library TITLE

I wrote it as a one-liner so it can easily be copy-pasted in a Shell window without the need for creating a separate PowerShell script.

5

Why not open the site in IE, open the library using "Open in Explorer Mode" from the ribbon, select all, right click and choose Properties, that should give you the actual size.

  • It might be OK, but if the library is versioned and you need the size it requires in the content DB, than it provides the wrong value, as it displays only the size of the actual versions (IMHO). – pholpar Nov 12 '18 at 13:09
0

Provided script examples and methods will work if you do not have versioning enabled in a library. Adding something like that for each item will count versions size:

$versions_size = 0;
foreach($v in $item.Versions)
{
   if (!$v.IsCurrentVersion)
   {
     $versions_size += $v.FileVersion.Size;
   }
}

Note, that "current version" in Versions collection has no reference to FileVersion.

I used similar script to collect information for all libraries in a farm. The difference of "plain" size and size with version data was considerable in my case. Like 2-3 times or so for some site collections. This helped to find out hidden "space eaters".

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.