Delete all Pages - Sharepoint Powershell
This post highlights how to remove all sub-sites or pages permanently from a specific SharePoint site collection/web using a PowerShell script.
Prerequisite
- Before using the below script user needs admin-level access.
- Change the site collection name as per your requirements.
NOTE: Use Below Script and kindly pass the valid URLs/List Name to execute the script.
Script:
Add-PSSnapin Microsoft.SharePoint.PowerShell
$site=Get-SPSite -identity <Your URL>
$subSiteColl=$site.RootWeb.Webs;
$subSites=@()
for($i= 0;$i -le $subSiteColl.Count-1;$i++)
{
$subSites +=$subSiteColl[$i];
}
foreach($subSite in $subSites){
$targetWeb=get-spweb -identity $subSite.URL;
$targetListGeneral=$targetWeb.lists["<List Name>"];
if($targetListGeneral){
for($x=$targetListGeneral.ItemCount-1;$x -ge 0; $x--)
{
$item=$targetListGeneral.Items[$x];
Write-Host "Deleting item id" $item.ID
$item.Delete();
}
$targetListGeneral.Update();
}
}
Thank you for reading my post!
Comments
Post a Comment