Click here to Skip to main content
13,291,690 members (61,050 online)
Click here to Skip to main content
Add your own
alternative version


Posted 22 Aug 2014

SharePoint 2010 - PowerShell Script to do the sizing - Includes all versions

, 22 Aug 2014
Rate this:
Please Sign up or sign in to vote.
PowerShell script which allows to get the sizing of any URLs for SharePoint 2010


SharePoint 2010 Content Inventory and Sizing tool 


Complete content inventory for selected site collections or for any sub-sites. The content inventory is exported as comma separated text file which can be easily possible to transform to any other file providing information about all sites and individual level size including versioning. A complete and up-to-date Content Inventory provides the following benefits:

  • Reusable and scalable PowerShell script
  • Helps to improve the overall content quality by identifying stale and abandoned sites and lists and their size
  • Documents the site structure and allows to verify that the structure
  • Input for better planning of easy to complex content migration project
  • Reduce the cost of third purchasing third party tool
  • Extensively re-used for doing content inventory and sizing for migration and moving content from one environment to another 

The Content Inventory is PowerShell script so no installation is required.

Using the code

Use PowerShell to run the code - 

I have seen many questions and answers and scattered code and answer to get the sizing of site collection or at any level which can also includes versions and will output a text file which will be comma seperated.

You can convert this C:\outputsize.txt to excel or any file format for further analysis.

Find below the complete code and  used several times in my environment SharePoint 2010 farm environment.

if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
Add-PsSnapin Microsoft.SharePoint.PowerShell

Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -path C:\outputsize.txt -append

function GetWebSize ($Web)
[long]$subtotal = 0
foreach ($folder in $Web.Folders)
$subtotal += GetFolderSize -Folder $folder
$SiteInGb = (($sitetotal/1024)/1024)/1024
$SiteInGb = "{0:N4}" -f $SiteInGb

write-host "," $Web.Url "," $SiteInGb "," 
write-host "`r`n"
return $subtotal

function GetSubWebSizes ($Web)
[long]$subtotal = 0
foreach ($subweb in $Web.GetSubwebsForCurrentUser())
[long]$webtotal = 0

foreach ($folder in $subweb.Folders)

$webtotal += GetFolderSize -Folder $folder
$subsiteInGb = (($subsitetotal/1024)/1024)/1024
$subsiteInGb = "{0:N4}" -f $subsiteInGb

write-host "," $subweb.Url "," $subsiteInGb ","
write-host "`r`n"
$subtotal += $webtotal
$subtotal += GetSubWebSizes -Web $subweb
return $subtotal

function GetFolderSize ($Folder)
[long]$folderSize = 0 
foreach ($file in $Folder.Files)
if ($file.Versions -ne $NULL -and $file.Versions.Count -gt 1) {
foreach ($version in $file.Versions)
$folderSize += $version.Size;
else {
$folderSize += $file.Length;
foreach ($fd in $Folder.SubFolders)
$folderSize += GetFolderSize -Folder $fd
return $folderSize

$web = Get-SPWeb $args[0]
[long]$total = 0
$total += GetWebSize -Web $web
$total += GetSubWebSizes -Web $web

$totalInMb = ($total/1024)/1024
$totalInMb = "{0:N4}" -f $totalInMb
$totalInGb = (($total/1024)/1024)/1024
$totalInGb = "{0:N4}" -f $totalInGb

write-host "Total size of all sites below" $StartWeb "is" $total "Bytes,"
write-host "which is" $totalInMb "MB or" $totalInGb "GB"


To run the above PowerShell - first copy the above code and save in a file with anyname.PS1 and fireup the PowerShell with administrator 

# how to run this script -

c:\>anyname.ps1 http://portal/


c:\>anyname.ps1 http://portal/portal1


c:\>anyname.ps1 http://portal/portal1/portal2

Points of Interest

Really time saving and very useful when your requirement is something to get all urls listing with size in GB.


You can get this information on internet but completly scattered and depending your requirement you can extend it to any level.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Abhi - Texas
United States United States
SharePoint Architect
My interests - Community, Collaboration and Computer Technologies

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 22 Aug 2014
Article Copyright 2014 by Abhi - Texas
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid