Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
1.8k views
in SharePoint Server by 39 47 55
edited by

In SharePoint 2019, I have a subsite that holds many subsites and when trying to delete the main subsite I got this error "Sites that have subsites or certain apps can't be deleted

Sorry, something went wrong
There was a problem deleting Web site "/subsite". Sites that have subsites or certain apps can't be deleted. Please try again after deleting all subsites and removing the apps.

Sites that have subsites or certain apps can't be deletedActually, I can't delete all subsites one by one, it's about 30 subsites, so I am looking for a PowerShell script that deletes all subsites under the parent site to avoid this error!


1 Answer

1 like 0 dislike
by 162 202 397
selected by
 
Best answer

Solving: Sites that have subsites or certain apps can't be deleted in SharePoint 2019

It's a logical error, you can't delete the parent site until delete all subsites under it, and to solve this issue, you have to loop for each subsite under the main site then delete subsites using PowerShell.

Delete Subsites using PowerShell in SharePoint 2019

To delete all subsites below the specific site, you have to do the following:

  1. Open Windows PowerShell As Administrator.
  2. Add PowerShell Snapin to Microsoft.SharePoint.
  3. The use the below PowerShell script to delete all subsites under specific main site.

Delete current site and all subsites using PowerShell

   Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
    $MainWeb= Get-SPWeb "your Parent Site URL"
    Foreach($SubSite in $MainWeb.Webs)
      {
         Write-host "Remove" $SubSite.Url
         Remove-SPWeb $SubSite -Confirm:$false
     }
        
      #Remove the main site
      Remove-SPWeb $MainWeb -Confirm:$false

See Also: Get All Site Collections and SubSites Per Farm

by 39 47 55
0 0
Thanks Mohamed
If you don’t ask, the answer is always NO!
...