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 Ajeet,
I got this error when i tried this script:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$WebApp=get-spwebapplication “http://site”
foreach ($SPSite in $webApp.Sites)
{
#get the collection of webs
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”
}
Get-SPWebApplication : Cannot find an SPWebApplication object with Name, Id, or Url: https://test.sharepoint..intranet.com/sitebasic
At C:\users\theravu-a\Desktop\New Text Document.ps1:3 char:29
+ $WebApp=get-spwebapplication <<<< “https://test.sharepoint..intranet.com/sitebasic“
+ CategoryInfo : InvalidData: (Microsoft.Share…tWebApplication:SpCmdletGetWebApplication) [Get-SPWebAppli
+ FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SpCmdletGetWebApplication
You cannot call a method on a null-valued expression.
At C:\users\theravu-a\Desktop\New Text Document.ps1:8 char:29
+ $SPSite.RecycleBin.DeleteAll <<<< ();
+ CategoryInfo : InvalidOperation: (DeleteAll:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Any reason for this error.