4

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?

2
  • 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.
    – Benny Skogberg
    Commented Nov 24, 2016 at 10:28
  • there is only one top level site. in first round loop is done. any i will try disposing objects Commented Nov 24, 2016 at 10:32

1 Answer 1

5

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(); 
}
3
  • Is there any PS command for Second stage Recycle Bin > OFF Commented Nov 24, 2016 at 13:06
  • 1
    $WebApp.RecycleBinEnabled = $FALSE; $WebApp.Update(); $WebApp.RecycleBinEnabled = $TRUE;` $WebApp.Update(); Commented Nov 25, 2016 at 3:10
  • Above commands also remove all recycle bin items. Commented Nov 25, 2016 at 3:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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