1

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.

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 
  • 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 '16 at 15:57
  • yes you can run any computer or server where sharepoint is installed Tool:"Sharepoint Management Shell Required" – S.P Mar 9 '16 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 '16 at 15:25
  • Would be better to use Get-SPOSite and Connect-SPOnline instead – Hybris95 Jul 26 '17 at 7:55
  • This won't work for SharePoint online but it's along the right lines. Have to recode using SPO cmdlets – Rob Nicholson Nov 12 '18 at 15:40
-1
  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 – Jayakumar Kulkarni Mar 8 '16 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 '16 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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