Skip to content

Commit

Permalink
Fixed recursive delete issue with Remove-SPOWeb.
Browse files Browse the repository at this point in the history
  • Loading branch information
glapointe committed Aug 26, 2016
1 parent cee9288 commit 2c1aff8
Show file tree
Hide file tree
Showing 4 changed files with 3,776 additions and 3,758 deletions.
2 changes: 2 additions & 0 deletions Cmdlets/Sites/NewSPOWeb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Sites
[RelatedCmdlets(typeof(ConnectSPOSite), typeof(GetSPOWeb))]
[Example(Code = "PS C:\\> New-SPOWeb -ParentWeb \"/\" -Url \"childsite\" -WebTemplate \"STS#0\" -Title \"Child Site\" -UseSamePermissionsAsParentSite",
Remarks = "This example creates a new child site with the URL name of childsite under the root Site of the current Site Collection.")]
[Example(Code = "PS C:\\> New-SPOWeb -ParentWeb \"/sites/sitecol1\" -Url \"childsite\" -WebTemplate \"STS#0\" -Title \"Child Site\" -UseSamePermissionsAsParentSite",
Remarks = "This example creates a new child site with the URL name of childsite under the sitecol1 Site of the current Site Collection (you must be connected to this site collection).")]
public class NewSPOWeb : BaseSPOCmdlet
{
[ValidateNotNullOrEmpty,
Expand Down
9 changes: 9 additions & 0 deletions Cmdlets/Sites/RemoveSPOWeb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,27 @@ private void Delete(Web web)
}
if (web.Webs.Count > 0)
{
var toDelete = new List<Web>();

foreach (Web childWeb in web.Webs)
{
toDelete.Add(childWeb);
}

foreach (Web childWeb in toDelete)
{
Delete(childWeb);
}
if (web.Webs.Count == 0)
{
try { WriteVerbose("Deleting " + web.Url); } catch { }
web.DeleteObject();
web.Context.ExecuteQuery();
}
}
else
{
try { WriteVerbose("Deleting " + web.Url); } catch { }
web.DeleteObject();
web.Context.ExecuteQuery();
}
Expand Down
Loading

0 comments on commit 2c1aff8

Please sign in to comment.