They are:
1. A script that will delete a web inside a Site Collection. So if you have a site in a Collection with a ton of sub sites, you won't have to go site-by-site and delete the subs, then the parents, up the tree.
2. A script that empties all user-level recycle bins in a Site Collection.
3. A script that clears the contents of a Site Collection Recycle Bin.
add-pssnapin Microsoft.SharePoint.Powershell
# This script completely deletes the specified Web (including all subsites).
function RemoveSPWebRecursively(
[Microsoft.SharePoint.SPWeb] $web)
{
Write-Debug "Removing site ($($web.Url))..."
$subwebs = $web.GetSubwebsForCurrentUser()
foreach($subweb in $subwebs)
{
RemoveSPWebRecursively($subweb)
$subweb.Dispose()
}
$DebugPreference = "SilentlyContinue"
Remove-SPWeb $web -Confirm:$false
$DebugPreference = "Continue"
}
$DebugPreference = "SilentlyContinue"
$web = Get-SPWeb "http://some.sharepointsite.com/sites/main/SubsiteToBeDeleted"
$DebugPreference = "Continue"
If ($web -ne $null)
{
RemoveSPWebRecursively $web
$web.Dispose()
}
*****
Add-PSSnapin Microsoft.SharePoint.Powershell
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint");
#This script will empty all Recycle Bins for all sites and subsites in a Site Collection.
$url = "http://some.sharepointsite.com/sites/main/"
$site = new-object microsoft.sharepoint.spsite($url)
for ($i=0;$i -lt $site.allwebs.count;$i++)
{
write-host $site.allwebs[$i].url "...deleting" $site.allwebs[$i].recyclebin.count "item(s)."
$site.allwebs[$i].recyclebin.deleteall()
}
write-host $site.url "...deleting" $site.recyclebin.count "item(s)."
$site.recyclebin.deleteall()
$site.dispose()
*****
Add-PSSnapin Microsoft.SharePoint.Powershell
#This script will delete the contents of the Site Collection Recycle Bin for a given Collection.
$sitecollectionUrl = “http://some.sharepointsite.com/sites/main/”
$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