Deleting all navigation nodes using CSOM PowerShell

It’s fairly straightforward to enumerate nodes in an array, in this example I’m deleting all the top navigation menu nodes in a SharePoint site. This is how I would normally loop through the top navigation menu:

As we are enumerating the nodes, we are removing nodes from the start and changing the position of the other nodes in the array. As the loop continues to run, it can skip positions of some of the nodes.

A solution which works better is looping through the array backwards. As you loop through the array backwards, it doesn’t change the position of items still in the array.

Your e-mail address will not be published. Required fields are marked *

Comment

Name *

Email *

Website

Tony Phillips

I’ve been working with Microsoft SharePoint since 2003 and specialise in branding, implementation and design of SharePoint installations. I’m a Microsoft Certified Professional and graduated from The University of Derby with BSc (Hons) in Digital Entertainment. I currently run a SharePoint and Office 365 consultancy business called Cloud Design Box Ltd. I work with clients across the UK and all over the world, please feel free to contact me via the contact page if you require consultancy or via twitter for general questions.