I need a powershell command which deletes the second stage recyclebin and the possibilities are stated below
Possibilities :
->If it is possible to get a script wherein if we give an user name for ex Deleted By “THEJA,Mr.RAVURI(THEJA)”,it should delete the all the files which were deleted by user.
->Another possibility is get the files based on Deleted which is like, the script should delete all the files which were deleted on specific date.
->to delete all the files which are present in the Admin recycle bin.
->to delete first “n” number of files which are present in recyclebin with ascending or descending order.
Many thanks in Advance and let me know if you require any clarifications on this
Theja.
Hi Theja,
Use following CmdLet
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$SPSiteurl =Â “https://test.sharepoint.intranet.com/sitebasic“
$spsite = Get-SPSite -Identity $SPSiteurl
$files =$spsite.Recyclebin |?{$_.ItemState -eq ‘SecondStageRecycleBin’}
foreach ($file in $files) {
$spsite.RecycleBin.Delete($file.ID)
}
And it will resolve your issue. Do let me know if works fine.
Hi Ajeet,
I tried with your suggestion and it is deleting both end user and admin recycle bin as well.I have tried by deleting some files and it went to end user recylebin and again i have moved few files to admin recyclebin.After this I have run this”$SPSite = get-spsite -identity “https://test.sharepoint.intranet.com/sitebasic“
$SPSite.RecycleBin.DeleteAll()” and it deleted files from both end user and admin recyelbin as well.If it is possible to delte only files from admin recylebin,Please provide me.
You have been very helpful for me regarding this script.
Many thanks,
Theja.
Hi Theja,
1st thing that you are passing sub site in web application because get-spwebapplication  is used to get the web application.
you can directly get site using $SPSite =Â get-spsite -identity “https://test.sharepoint.intranet.com/sitebasic“.
2nd no need to use foreach loop.
you can directly $SPSite.RecycleBin.DeleteAll()
let me know if still facing issue
Hi Ajeet,
Let we assume my site collection would be https://test.sharepoint.intranet.com/sitebasic  then the script for deleting 2nd leven recycle bin alone goes as follows:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$WebApp=get-spwebapplication “https://test.sharepoint.intranet.com/sitebasic“
foreach ($SPSite in $webApp.Sites)
{
#get the collection of webs
#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”
}
After running this script also i get the same error..I use sharepoint 2010.
Please let me know where i went wrong…:(
thanks.
Â
Please replace “http://site” with your actual site 🙂