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 donot have Team viewer with me and I can show you via webex and please find the error screenshots for the rest scripts I have got .
I could not get this
here “ is showing a bit different in your script. Can you please change both(Starting and Ending) ” with “
Would you mind in eloborating me 🙂
$query.ItemState = “SecondStageRecycleBin”;
here “ is showing a bit different in your script. Can you please change both(Starting and Ending) ” with “
Also, If possible can you share your screen on TeamViewer
Hi Ajeet,
Please find the attachement for the error I have got after i ran the script:
When you ae using for ‘n’ numbers, then yes.
Else try this. It will definitely work :):
$site = Get-SPSite -Identity $SPSiteurl
$query = new-object Microsoft.SharePoint.SPRecycleBinQuery;
$query.ItemState = “SecondStageRecycleBin”;
$query.RowLimit = 2 #Set here ‘n’ numbers of item.I have set it to 2;
$files= $site.GetRecycleBinItems($query);
$spsite.RecycleBin.Delete($file.ID)
}
Hi Ajeet,
The error which i havae got is as follows:
You cannot call a method on a null-valued expression.
At C:\users\theravu-a\Desktop\deleted by username.ps1:11 char:26
+ $SPSite.RecycleBin.Delete ($file.ID)
+ CategoryInfo : InvalidOperation: (Delete:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\users\theravu-a\Desktop\deleted by username.ps1:11 char:26
+ $SPSite.RecycleBin.Delete ($file.ID)
+ CategoryInfo : InvalidOperation: (Delete:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\users\theravu-a\Desktop\deleted by username.ps1:11 char:26
+ $SPSite.RecycleBin.Delete ($file.ID)
+ CategoryInfo : InvalidOperation: (Delete:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\users\theravu-a\Desktop\deleted by username.ps1:11 char:26
+ $SPSite.RecycleBin.Delete ($file.ID)
+ CategoryInfo : InvalidOperation: (Delete:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\users\theravu-a\Desktop\deleted by username.ps1:11 char:26
+ $SPSite.RecycleBin.Delete ($file.ID)
+ CategoryInfo : InvalidOperation: (Delete:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
This is the actual error I have got and the same error gets repeated for the other too scripts too..I have tested this in fresh powershell and the repeats.
I have observed this in cmdlet you have provided me :
$site = Get-SPSite -Identity $SPSiteurl
$query = new-object Microsoft.SharePoint.SPRecycleBinQuery;
$query.ItemState = “SecondStageRecycleBin”;
#$query.RowLimit = 2 #Set here ‘n’ numbers of item.I have set it to 2;
$itemcoll = $site.GetRecycleBinItems($query);
this # (underlined by me )should be there or before $query.Rowlimit =2 as this goes like comment as per my little powershell knowledge.
Please let me know where i went wrong..
Many thanks for spending your valuable time for this ..:)