PowerShell Tip: Empty SharePoint Site Collection Recycle Bin

powershellSaving time, once again, with PowerShell

Have you ever ended up with a very large number of items in your SharePoint Site Collection recycle bin?

Sometimes, certain projects that involve migrations or large changes can fill up your bin with all of the items that didn’t make it to the next round.

More than likely, your recycle bin was similar to mine and only displays 50 items per page. For a recycle bin which contains thousands of items, I don’t have to do the math for you to realize that it would take a very long time to empty page by page.

This can happen for any number of reasons, but I’ll share how I ended up with such a large recycle bin and how I ultimately emptied the entire thing in just minutes.

How I overloaded my Recycle Bin:

I was recently performing a migration from WSS 2007 to SharePoint 2010 using our third-party migration tool, the Metavis Migrator.

During the migration, I ran into a few issues in regards to user mappings. Working with the fantastic Metavis Support Team, we resolved the issue and could successfully perform the migration again. But this particular site had a list with over 27,000 items in it, and because I had to attempt the migration of this site multiple times, I ended up with over 70,000 items in the recycle bin!

Like I said above, that would take a very, very long time only emptying 50 items at a time.

How did I empty the entire Recycle Bin?

One word – PowerShell.

Empty entire Site Collection Recycle Bin using PowerShell:

  1. Browse to the Start Menu. Search for “PowerShell”, select Windows PowerShell ISE. (I am running Windows 2012 in this example. The steps to open PowerShell ISE may differ if using another Operating System). Select PowerShell
  2. Copy the below command into PowerShell. Update the Site Collection URL to match the appropriate site.
 $sitecollectionUrl = “http://domainname.com/sitecollectionurl”$siteCollection = New-Object Microsoft.SharePoint.SPSite($sitecollectionUrl)write-host(“Items to be deleted : ” +$siteCollection.RecycleBin.Count.toString())$now = Get-Datewrite-host(“Deleting started at ” +$now.toString())$siteCollection.RecycleBin.DeleteAll();$now = Get-Date

write-host(“Deleting completed at ” +$now.toString())

$siteCollection.Dispose();

  1. Once you have updated the Site Collection URL, execute the command by clicking on the Run Script button on the PowerShell toolbar. PowerShell toolbar run script

Depending on how many items are in the recycle bin, this could take a few minutes. When the command is executing, the red stop button (two to the right of the Run Script button) will be illuminated. When the command is completed, the Run Script button will be illuminated once again.

When the command is completed, you can verify if it was successful. Chances are, if the command did not display any errors, all items have been deleted. Simply browse to the appropriate SharePoint site to determine if the Site Collection recycle bin is now empty.

As stated above, the recycle bin I was working with had approximately 70,000 items. I executed the command, knowing it would take some time. I checked back about 20 minutes later and it was completed. An easy way to check progress is by monitoring the recycle bin while the command is executing. You will be able to refresh the page and watch the number of items decrease.

That’s it! Please comment below with any questions.

VN:F [1.9.22_1171]
Rating: 8.6/10 (8 votes cast)

About Fpweb.net Crew

Our business is centered on bringing enterprise-class strategy, support, and security to your hosted or managed platforms no matter where you choose to deploy your environment. We specialize in providing managed services, cyber security, and expert, USA-based, 24/7 Absolute Support® on-premises, or in any cloud.
This entry was posted in PowerShell, SharePoint Tips & Tricks and tagged , , , , , , . Bookmark the permalink.

4 Responses to PowerShell Tip: Empty SharePoint Site Collection Recycle Bin

  1. Meen Bamm says:

    Can you give the powershell command to restore all items in recycle bin with days to choose. I search Google and the command I found doesn’t work.

    This is what I used.

    $recyclebinitems = (Get-SPWeb “_http://” ).RecycleBin foreach($recyclebinitem in $recyclebinitems)
    {
    (Get-SPWeb “_http://”).RecycleBin.Restore($recyclebinitem.ID)
    }

    ——————————————–
    The above command seems to be missing something..

    Thank you..
    Meen

  2. Will says:

    Any reason why you’re using new-object instead of Get-SPSite to instantiate the site?

  3. miroslaw_ziolkowski says:

    This one works for deletion:
    $recyclebinitems = (Get-SPSite “http://”).RecycleBin
    foreach($recyclebinitem in $recyclebinitems)
    {
    (Get-SPSite “http://”).RecycleBin.Delete($recyclebinitem.ID)
    }

  4. Andrey says:

    Hi, Joe!
    In your example you use Win Powershell ISE. However, by default your script wouldn’t work, because it doesn’t have a link to SharePoint snap-in.
    May be you add to the 1st line of your code:
    Add-PSSnapin “Microsoft.SharePoint.PowerShell”

    It would be more esier for readers to use it.

Leave a Reply

Your email address will not be published. Required fields are marked *

Let's make sure you're human first: *