2

Is there a way to batch delete all items in the recycle bin on the client side in SharePoint Online?

I've tried using javascript:emptyItems() in the browser but this appears to time out after removing about 2k items. I have 1.5 million items and growing and would like to empty all at once and have a quick and easy way to do this going forward. Is there a way to do this using JSOM, CSOM or REST API?

I'm open to anything which doesn't involve central admin or server side access. Any direction would be appreciated.

3 Answers 3

0
  1. First Navigate to the recycle bin page (e.g.,http://localhost/_layouts/recyclebin.aspx).
  2. Remove the address from address bar, type “javascript:emptyItems()” (Remove the quotes) Press Enter.
  3. It will be asked if you really want to empty the recycle bin. Click OK to empty it; click Cancel to leave it alone.
2
  • Just try this setting then no need to do any coding for that Commented Mar 8, 2016 at 5:37
  • This was the first thing I tried. It just hangs after deleting a couple of thousand records. I let it run overnight and no difference.
    – Nate
    Commented Mar 8, 2016 at 15:56
0

you can achieve by power-shell save below Code in ps1 dont Forget to change site url from code and Run through managment Shell

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

function Remove-SPSiteSecondStageRecycleBin() 
{

    [Microsoft.SharePoint.SPSite] $siteCollection = Get-SPSite "http://sp:2000/sites/test" -ErrorAction Stop


    $recycleQuery = New-Object Microsoft.SharePoint.SPRecycleBinQuery;
    $recycleQuery.ItemState = [Microsoft.SharePoint.SPRecycleBinItemState]::SecondStageRecycleBin;
    $recycleQuery.OrderBy = [Microsoft.SharePoint.SPRecycleBinOrderBy]::Default;

    $recycledItems = $siteCollection.GetRecycleBinItems($recycleQuery);

    $count = $recycledItems.Count;

    for($i = 0; $i -lt $count; $i++)
    {
        $g = New-Object System.Guid($recycledItems[$i].ID);
        $recycledItems.Delete($g);
    }


    $siteCollection.Dispose()
}

Function Load-SharePoint-Powershell
{ 
    Write-Host "TEST"
    if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
    {    
          Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction Stop

    }

}


Load-SharePoint-Powershell
Remove-SPSiteSecondStageRecycleBin 
5
  • I know very little about powershell. Do you have to run this on the SharePoint server or can you execute it from any computer?
    – Nate
    Commented Mar 8, 2016 at 15:57
  • yes you can run any computer or server where sharepoint is installed Tool:"Sharepoint Management Shell Required"
    – S.P
    Commented Mar 9, 2016 at 4:25
  • From what I could find on this it looks like you need central admin access to run it, which unfortunately I don't have. support.office.com/en-us/article/…
    – Nate
    Commented Mar 9, 2016 at 15:25
  • Would be better to use Get-SPOSite and Connect-SPOnline instead
    – Hybris95
    Commented Jul 26, 2017 at 7:55
  • 1
    This won't work for SharePoint online but it's along the right lines. Have to recode using SPO cmdlets Commented Nov 12, 2018 at 15:40
0

if your open to rest than use the following api

site collection level (second stage bin):

/_api/site/RecycleBin/deleteAll()  

web level (first stage bin):

/_api/web/RecycleBin/deleteAll()  

its a post method!

https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-visio/jj246426%28v%3doffice.15%29

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.