In the recycle bin there are 176100 items. I have tried to remove them using PowerShell but it is unable to remove all. After sometime it stops and gives an error. Tried following PowerShell.

$WebApp=get-spwebapplication "http://xxxx:31150/"

foreach ($SPSite in $webApp.Sites)
{
#get the collection of webs
foreach($SPWeb in $SPSite.AllWebs)
{
write-host "deleting recycle bin for:"
write-host $SPWeb.title ":" $SPWeb.URL "`n"
#Empty the 1st Stage Recycle bin items PERMENANTLY
$SPWeb.RecycleBin.DeleteAll();

#Send the 1st Stage Recycle bin items to 2nd Stage
$SPWeb.RecycleBin.MoveAllToSecondStage();

}
#Empty SharePoint site collection recycle bin (Second Stage Recycle bin) or Admin Recycle bin
$SPSite.RecycleBin.DeleteAll();

write-host "Administrator Recycle bin Items Deleted for:" $SPSite.RootWeb.title "`n"
}

In the database there is a table called dbo.RecycleBin. So my question: Is there any risk if I delete all rows from this table?

  • Two points! (1) You never dispose the web-, or site objects which can cause PowerShell to malfunction if you have many sites. (2) Never ever change anything in a SharePoint database. You will void warranty from Microsoft, and can't get support. – 4rchit3ct Nov 24 '16 at 10:28
  • there is only one top level site. in first round loop is done. any i will try disposing objects – Atish Dipongkor Nov 24 '16 at 10:32
up vote 5 down vote accepted

Don't touch the database, but instead of deleting items from 2nd stage Recycle Bin using PowerShell, try disabling it from Central Admin first before running the PS script:

Central Administration > Application Management > Web Application General Settings > Set Recycle Bin > Second stage Recycle Bin > OFF

Or using PS:

$WebApp.RecycleBinEnabled = $false; 
$WebApp.Update(); 
$WebApp.RecycleBinEnabled = $true; 
$WebApp.Update();

This should empty the recycle bin, but for more gradual deletion, you could try it like this (notice the Disposes):

$WebApp=get-spwebapplication "http://xxxx:31150/"

foreach ($SPSite in $webApp.Sites)
{
    #get the collection of webs
    foreach($SPWeb in $SPSite.AllWebs)
    {
     write-host "deleting recycle bin for:"
     write-host $SPWeb.title ":" $SPWeb.URL "`n"
     #Empty the 1st Stage Recycle bin items PERMENANTLY
     $SPWeb.RecycleBin.DeleteAll();    
     #Don't think you need to call MoveAllToSecondStage() here anymore as you've just deleted all items permanently, but I could be wrong.
     $SPWeb.Dispose();
    }   

    $SPSite.Dispose(); 
}
  • Is there any PS command for Second stage Recycle Bin > OFF – Atish Dipongkor Nov 24 '16 at 13:06
  • 1
    $WebApp.RecycleBinEnabled = $FALSE; $WebApp.Update(); $WebApp.RecycleBinEnabled = $TRUE;` $WebApp.Update(); – Atish Dipongkor Nov 25 '16 at 3:10
  • Above commands also remove all recycle bin items. – Atish Dipongkor Nov 25 '16 at 3:11

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.