Empty SharePoint Recycle Bins Programmatically with PowerShell

Empty SharePoint Site Collection Recycle bin using PowerShell:
Recycle bin in SharePoint is a container used to retain deleted items such as list items, documents, document libraries, lists, and sites to a number of days defined by the SharePoint administrator. Deleted items in recycle bin can be restored if needed. Here is the PowerShell script to empty SharePoint recycle bin.

#Get the Site Collection$Site = Get-SPSite "https://portal.crescent.com/sites/test" #Delete all from 1st Stage Recycle bin$Site.AllWebs | Foreach-object { $_.RecycleBin.MoveAllToSecondStage() } #Empty 2nd Stage Recycle bin$Site.RecycleBin.DeleteAll();

This deletes all items from recycle bin in SharePoint 2016 using PowerShell.

Add-PSSnapinMicrosoft.SharePoint.PowerShell -ErrorActionSilentlyContinue$WebApp=Get-SPWebApplication"http://intranet.crescent.com"foreach($SPSitein $webApp.Sites){#get the collection of websforeach($SPWebin $SPSite.AllWebs){#Empty the 1st Stage Recycle bin items PERMENANTLY#$SPWeb.RecycleBin.DeleteAll();#Send the 1st Stage Recycle bin items to 2nd Stage$SPWeb.RecycleBin.MoveAllToSecondStage();write-host"End-User Recycle Bin Items Deleted for:"write-host$SPWeb.title ":"$SPWeb.URL "`n"#Dispose Web object$SPWeb.Dispose()}#Empty SharePoint site collection recycle bin (Second Stage Recycle bin) or Admin Recycle bin$SPSite.RecycleBin.DeleteAll();#Dispose Site object$SPSite.Dispose()write-host"Administrator Recycle bin Items Deleted for:"$SPSite.RootWeb.title "`n"}

#Read more: https://www.sharepointdiary.com/2012/08/empty-sharepoint-recycle-bins-programmatically-powershell.html#ixzz6Q6VSBgND

PowerShell Script to Empty SharePoint Recycle Bins Programmatically:
Lets empty the recycle bin of all site collection under a given web application. Here is the PowerShell to delete all items in recycle bin.

Leave a Reply

Your email address will not be published. Required fields are marked *