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

  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.
  • Just try this setting then no need to do any coding for that 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
    Mar 8, 2016 at 15:56

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


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);


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



  • 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
    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
    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
    Mar 9, 2016 at 15:25
  • Would be better to use Get-SPOSite and Connect-SPOnline instead
    – Hybris95
    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 Nov 12, 2018 at 15:40

if your open to rest than use the following api

site collection level (second stage bin):


web level (first stage bin):


its a post method!


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.