Delete all items in Recycle bin by PowerShell

We were doing testing and we generated lots of documents and lists and needed to eliminate those documents, so instead of eliminating files one by one we used the following PS code:

$WebApp=get-spwebapplication "https://yourappweb"

foreach ($SPSite in $webApp.Sites)
{
#get the collection of webs
foreach($SPWeb in $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"
}
#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"
}

hope it helps!

Advertisement

4 thoughts on “Delete all items in Recycle bin by PowerShell

    1. When I was doing this, I was deleting all the objject, so, I didn’t have the necessity to filter by user. If you’re able to do this, I will be interested in knowing the solution

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s