Skip Ribbon Commands
Skip to main content

Quick Launch

Todd Klindt's home page > Todd Klindt's Office 365 Admin Blog > Posts > Using PowerShell to find site collection size in SharePoint 2010
June 07
Using PowerShell to find site collection size in SharePoint 2010

Today on Twitter I received a message from Nik Patel:

“How would I determine the site collection size using powershell? I am sure you have figured it out.. ;)”

As luck would have it, I had. The good news is that PowerShell exposes that information pretty easily. Even an admin like myself can figure it out. Let’s walk through how I put this all together. First I set a variable to a site collection so that I could take a look at the properties that were exposed.

$sc = get-spsite http://sharepoint

$sc | get-member

From here I saw the Usage property. That looks promising. executed $sc.usage did give me the storage used by a site collection, but it looked a bit more complicated:

PS C:\> $sc.Usage

Storage           : 9621220
Bandwidth         : 0
Visits            : 0
Hits              : 0
DiscussionStorage : 0

I only wanted the storage usage, so I needed a good way to pull all that out. Plus I needed it for all the site collections, not just one. That lead me to this line:

Get-SPSite | select url, @{label="Size in MB";Expression={$}}

This gives me the information I wanted, but the presentation leaves a bit to be desired. This line worked a little better:

Get-SPSite | select url, @{label="Size in MB";Expression={$}} | Sort-Object -Descending -Property "Size in MB" | Format-Table –AutoSize

This gave me the storage usage in megabytes instead of bytes, sorted the site collections by size, and formatted it all nicely. To go for the gold I decided to take it one step farther:

Get-SPSite | select url, @{label="Size in MB";Expression={$}} | Sort-Object -Descending -Property "Size in MB" | ConvertTo-Html -title "Site Collections sort by size" | Set-Content sc.html

This takes the output from above and writes it to an HTML file for easier viewing.

You can view the entire transcript and the HTML output if you’d like.

Happy PowerShelling.




Thanks for taking time to write about this.. much needed.. Somehow I thought you already had this. I must have seen you doing this in one of your technet videos or conferences. ;)

Anyways, looking forward to see you at SPSChicago this saturday. I am speaking at the PM on InfoPath..
 on 6/7/2011 11:42 PM

Cool, but leaves out 2nd stage Recycle Bin... ;)

I've written this function a while ago which calculates total size, including the 2nd stage Recycle Bin, which is not included in Usage:

 Returns the total size of a site collection, including the second-stage recycling bin, in Megabytes rounded to 2 fractional digits.

 TypeName: Microsoft.SharePoint.SPSite
function Measure-SPSite ($sc)
    ## If something goes wrong, silently return nothing
    trap {return $null; continue};
    ## Initialise Recycle Bin Query object
    $rbquery = New-Object -TypeName Microsoft.SharePoint.SPRecycleBinQuery;
    $rbquery.ItemState = [Microsoft.SharePoint.SPRecycleBinItemState]::SecondStageRecycleBin;
    ## Specify that the query should return maximum number of objects (i.e. all)
    $rbquery.RowLimit = [int]::MaxValue-1;
    ## Get the sum of values of the 'Size' property of all Recycle Bin items and assign it to a variable
    $rbsize = $sc.GetRecycleBinItems($rbquery) |
        Measure-Object -Property Size -Sum |
            Select-Object -ExpandProperty Sum;
    ## Calculate the value in Mbs and returned the rounded value to the caller       
    return ([System.Math]::Round((($sc.Usage.Storage+$rbsize)/1Mb),2));
 on 6/8/2011 3:50 AM

How can I also get the size of the individual subsites

This is great. I'd like to take it a step further by listing the size of each individual subsite in each site collection as well. How to do that?
 on 6/8/2011 9:43 AM


Any reason you didnt just use

Get-SPSiteAdministration | ft url,diskused -AutoSize

Is the data any different?
 on 6/9/2011 11:33 AM

A good backup of your content ;-)

 on 6/16/2011 1:13 AM

Re: A good backup of your content ;-)

I'm kind of on the fence whether I like that or not. On one hand the author is very upfront and transparent that it's my content. He makes no effort to pass it off as his own. I really appreciate that. A lot of people don't have them kind of integrity. On the other hand I do like the page views, and if his blog post shows up higher than mine for whatever reason he gets the views. Plus, he has ads on his site, so potentially he's making money off of my content.

I'm torn on it. Thoughts?

Todd O. KlindtNo presence information on 6/16/2011 9:26 AM


We are all making money off you Todd, one way or another.

The Get-SPSiteAdministration suggestion mentioned above worked for me.

FYI - the "todays date" captcha has yet to be internationalised. Its already Monday here in Australia. Suggest changing it to "What is the current date in Des Moines?"
 on 6/19/2011 9:26 PM

re: How can I also get the size of the individual subsites

I don't know any way to get the size of webs with PowerShell. Sorry.

Todd O. KlindtNo presence information on 6/25/2011 10:29 AM

Re: Difference

Different ways to do the same thing. Get-SPSiteAdministration is probably a better way to hande it, as it lets you access Site Collections you don't have access to as a user.

Todd O. KlindtNo presence information on 6/25/2011 10:55 AM

Re: Get-SPSiteAdministration

Certainly you recognize there are okay and not-okay ways to make money off of my blog, don't you? I think copying my work in its entirety to another blog that is ad supported crosses that line into not-okay. Using PowerShell scripts you find here at your job is clearly Okay.

The today's date field doesn't actually have to be "today's" date. It can be any valid date. Don't tell the spammers that though.

Todd O. KlindtNo presence information on 6/25/2011 10:57 AM
1 - 10Next

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.


Body *

Today's date *

Select a date from the calendar.
Please enter today's date so I know you are a real person


Want a message when I reply to your comment? Put your Twitter handle here.