0

I have created a script that adds my search nav to my search site but it is still left with what was already there as out of the box. I am having trouble with finding how I can delete the nodes I don't want. Here is my code at the moment :

$Navigation = $ctx.Web.Navigation
$searchNavigation = $Nav.GetNodeById(1040);
$nodeC=$searchNavigation.Children
$ctx.Load($nodeC)
$ctx.ExecuteQuery()
foreach ($Node in $nodeC)
{
    $Node.DeleteObject()


}

this doesn't delete the nodes, just give the error

Error while creating search result page. Error -->> The collection was modified. Enumeration operation may not execute

1 Answer 1

2

Instead of using foreach loop, try performing operation using a for loop.

for($node=0;$node -lt $nodeC.Count;$node++){
$nodeVal = $nodeC[$node];
$nodeC.Delete($nodeVal);}
2
  • For completeness, can you please add a code example that uses a for-loop in above scenario Commented Jan 13, 2015 at 11:40
  • Added Code example
    – 404
    Commented Jan 13, 2015 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.