kwizcom banner advertisement

Get SharePoint Recycle Bin Storage Size

In a Database attachment method migration project, wanted to get the insights on how much space being occupied by SharePoint Admin Recycle bin for all site collections. There were 3000+ site collections.

PowerShell Script to get First Stage recycle bin size:
function global:Get-SPSite($url) {
    return new-Object Microsoft.SharePoint.SPSite($url)
function Get-RecyclebinSize($SiteURL)
    #Get the site collection
    $site = Get-SPSite $SiteURL
    # Create SPRecycleBinQuery object to Query Reycle bin
    $SPRecycleBinQuery = New-Object -TypeName Microsoft.SharePoint.SPRecycleBinQuery
    $SPRecycleBinQuery.ItemState = [Microsoft.SharePoint.SPRecycleBinItemState]::FirstStageRecycleBin
    # Set the query should return maximum number of objects 
    $SPRecycleBinQuery.RowLimit = [int]::MaxValue-1
    # Get the sum of values of the 'Size' property of all Recycle Bin items and assign it to a variable
    $RecycleBinSize = $site.GetRecycleBinItems($SPRecycleBinQuery) | 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(($RecycleBinSize/1Mb),2))

 $Size = Get-RecyclebinSize ""
 write-host "First Stage Recycle bin Size (in MB):" $size 

Here is the PowerShell script to get the 2nd stage recycle bin's size in SharePoint 2010:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

$WebApp=get-spwebapplication ""

    foreach ($SPSite in $WebApp.Sites)
     # SPRecycleBinQuery to Query Reycle bin    
     $SPRecycleBinQuery=new-object Microsoft.SharePoint.SPRecycleBinQuery
     $SPRecycleBinQuery.OrderBy = [Microsoft.SharePoint.SPRecycleBinOrderBy]::DeletedDate;
     $SPRecycleBinQuery.IsAscending = $false;
     $SPRecycleBinQuery.RowLimit = 2000
     $SPRecycleBinQuery.ItemState = [Microsoft.SharePoint.SPRecycleBinItemState]::SecondStageRecycleBin
     $SPRecycleBinItemCollection  = $SPSite.GetRecycleBinItems($SPRecycleBinQuery)
        for ($i=$SPRecycleBinItemCollection.Count-1; $i -GE 0;  $i--)
                        $guid = $SPRecycleBinItemCollection[$i].ID;
          write-host "Recycle bin Size in" $SPSite.RootWeb.Title "-"  $SPSite.RootWeb.URL ":" ($size/1MB)   
Get SharePoint Recycle Bin Storage Size Get SharePoint Recycle Bin Storage Size Reviewed by Salaudeen Rajack on August 01, 2012 Rating: 5


  1. thank you . excellent post

  2. Salaudeen,
    Great post. I suggest an update for the second stage recycle bin size script. When you set the row limit to a value you need to cycle the collection until all the items are counted. In the above example you will only find the size of the first 2000 items.

    $SPSite = Get-SPSite http://webapp/site
    #SPRecycleBinQuery to Query Reycle bin
    $SPRecycleBinQuery=new-object Microsoft.SharePoint.SPRecycleBinQuery
    $SPRecycleBinQuery.RowLimit = 2000
    $SPRecycleBinQuery.ItemState = [Microsoft.SharePoint.SPRecycleBinItemState]::SecondStageRecycleBin
    $SPRecycleBinItemCollection = $SPSite.GetRecycleBinItems($SPRecycleBinQuery)
    $SPRecycleBinQuery.ItemCollectionPosition = $SPRecycleBinItemCollection.ItemCollectionPosition

    For($i=$SPRecycleBinItemCollection.Count-1; $i -GE 0; $i--)
    $Size += $SPRecycleBinItemCollection[$i].Size
    While ($SPRecycleBinQuery.ItemCollectionPosition -Ne $Null)
    Write-Host "Recycle bin size in" $SPSite.RootWeb.Title "-" $SPSite.RootWeb.URL ":" ($size/1MB)

  3. Hello,

    Can you please help me in modifying the script to consolidate both first stage and second stage recycle bin into single script and export to csv. Its bit urgent.

    Thanks in Advance.


Please Login and comment to get your questions answered!

Powered by Blogger.