Delete SharePoint sites recursively
Today I tried to delete a SharePoint site (SPWeb) with child sites inside. I tried to delete it form administrator interface but I got an error. Something was wrong with templates or site structure. So I decided to use PowerShell for SharePoint.
I entered "Remove-SPWeb http://spdev/folder/" and pressed enter, but I got an error that this site has child sites and cannot be deleted.
So I decided to write a PowerShell script for removing:
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://spdev/folder/"
$DebugPreference = "Continue"
If ($web -ne $null)
{
RemoveSPWebRecursively $web
$web.Dispose()
}

Login as another user in SharePoint 2019 on-premises site in Chrome
Set limited Wi-Fi connection within command line in Windows
A sticker problem with the fan in HP laptop