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?

有帮助吗?

解决方案

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(); 
}
许可以下: CC-BY-SA归因
scroll top