Empty Recycle Bin in All SharePoint Sites

Continuing from my previous post to reduce SharePoint Content Database for test environment by deleting version histories for all libraries in SharePoint Site Collection.

We could also reducing SharePoint Content Database by Emptying all Recycle Bin. Below is the powershell script to do it

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
# get site
$site = new-object Microsoft.SharePoint.SPSite(<a href="http://sitename/">http://sitename</a>)
# loop through webs
foreach ($web in $site.AllWebs)
{
   $web.RecycleBin.MoveAllToSecondStage();
   write-host $web.title ":" $web.URL
}
$site.RecycleBin.DeleteAll();
write-host $site.RootWeb.title ":" $site.RootWeb.URL

$web.Dispose();
$site.Dispose();

NOTE: DO NOT forget to set your PowerShell execution policy to Remotely Signed

Set-ExecutionPolicy RemoteSigned
Advertisements

Tagged: , ,

One thought on “Empty Recycle Bin in All SharePoint Sites

  1. […] Another thing that you could do to reduce SharePoint Content Database is by emptying all recycle bin in site collection. […]

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: