Skip to main content

Powershell Script to empty admin recyle bin in SharePoint

a script wherein if we give an user name for ex Deleted By "Bai,Mala(Mala)",it should delete the all the files which were deleted by user.


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$siteURL = "your site url"
$site= New-Object microsoft.sharepoint.spsite($siteURL)
$query = new-object Microsoft.SharePoint.SPRecycleBinQuery;
$query.ItemState = “FirstStageRecycleBin”;
$itemcoll = $site.GetRecycleBinItems($query);

#Delete items those are deleted by Mala

$files= $itemcoll | where {$_.DeletedByName -match "your name"}

#Delete output
foreach ($file in $files) {
$site.RecycleBin.Delete($file.ID)

}

Comments

Popular posts from this blog