How to Get the Size of the Document with and Without Version in SharePoint using PowerShell Script – Server-Side Object Model

Sathish Nadarajan
SharePoint MVP
Published On :   13 Mar 2018
Visit Count
Today :  3    Total :   323
Plan, Migrate, Secure, Report
SharePoint & Office 365 Tool. Simple & Easy to Use. 15-Day Trial!

SharePoint Office 365 Tool
Simple & Powerful Tool for Migration, Security & Reporting. Free Trial

Recently faced an interesting requirement to get the Size of the Documents with and Without Version during the preparation of Inventory in one of the Migration assignment.

Usually, we can get the size of the Web Site from the admin console itself. But, it will give you the size including the Versions of the documents. But if the customer wants to migrate only the final version, then the size may not be realistic.

To be precise, if the size of the Web shows as 20 GB in the Console, and the requirement is to migrate only the final version, then the content migrated would be only 5 GB. (The numbers which I am referring are for example purpose only.) Hence, the remaining 15 GB, we don’t event consider for our planning.

The below piece of PowerShell Script will give you both the Options.

 function GetSPFolderSize ($Folder)
    $byteCount = 0   
         # calculate the files in the immediate folder    
         foreach ($SPFile in $Folder.Files)    
             $byteCount += $SPFile.TotalLength 
             # The below line will include the versions  
               foreach ($SPFileVersion in $SPFile.Versions)   
                 $byteCount += $SPFileVersion.Size   
         # Handle sub folders     
         foreach ($SubFolder  in $Folder.SubFolders)    
             $byteCount += GetSPFolderSize  $SubFolder
     return $byteCount  

To call the method,

 $webBytes = GetSPFolderSize  $Web.RootFolder
The $webBytes variable will contain the size in Bytes.

Happy Coding,

Sathish Nadarajan.

SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.

Migratiin Tools for SharePoint