Friday, August 9, 2013

Empty SharePoint Recycle bin using PowerShell

Below script will delete all the Items from the Recycle bin and Site Collection recycle bin in SharePoint.

if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-null

$sitecollectionUrl = http://sitename:portnumber
$siteCollection = New-Object Microsoft.SharePoint.SPSite($sitecollectionUrl)
write-host("Items to be deleted : " +$siteCollection.RecycleBin.Count.toString())
$now = Get-Date
write-host("Deleting started at " +$now.toString())
$siteCollection.RecycleBin.DeleteAll();
$now = Get-Date
write-host("Deleting completed at " +$now.toString())
$siteCollection.Dispose();

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...