Below script deletes All Recycle Bin items in SharePoint 2007. Wanted help to modify the script to delete only items older than 3 months.


$sitecollectionUrl = "http://domainname.com/sitecollectionurl"
$siteCollection = New-Object Microsoft.SharePoint.SPSite($sitecollectionUrl)
write-host("Items to be deleted : " +$siteCollection.RecycleBin.Count.toString())
$now = Get-Date 
write-host("Deleting started at " +$now.toString())
$now = Get-Date
write-host("Deleting completed at " +$now.toString())


  • When you say "items" older than 3 months, do you mean List Items, as in only items deleted from a SharePoint List? Or do you mean any object that's been in the Recycle Bin for more than 3 months. up to & including sub-sites, lists, libraries, folders, documents & list items? – Stevangelista Jun 14 '16 at 3:40

This script will accomplish the goal, at least in SP2010/2013/2016. I don't have access to an SP2007 box but you should easily be able to replace my use of the Get-SPSite cmdlet with the new-object sytnax.

$SPSite = Get-SPSite "http://YourHostName.net/sites/YourSiteCollection"

# Set this to any positive integer; items more than this many days old will be deleted
$DaysOldToDelete = 90

# This only deletes items deleted from an SP List or Library; tweak or remove the $_.itemtype filter as needed
$SPRecycleBinItems = $SPSite.RecycleBin | where { $_.itemstate -eq "FirstStageRecyclebin" -and $_.DeletedDate -lt (Get-Date).AddDays(-$DaysOldToDelete) -and ($_.itemtype -eq "ListItem" -or $_.itemtype -eq "File")}
foreach ($ItemToDelete in $SPRecycleBinItems) {
    $ItemGUID = new-object system.guid($ItemToDelete.ID);
| improve this answer | |
  • Hi Stevangelista.. Thanks so much for the quick response. I meant deleting any object that's been in the Recycle Bin for more than 3 months – david Jun 15 '16 at 0:45
  • No problem; per the inline comment, you can just remove the $_.itemtype conditions from the where clause and it will delete anything & everything in the Stage One Recycle Bin that's older than the number of days your $DaysOldToDelete variable is set to. – Stevangelista Jun 15 '16 at 1:39

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.