protected override void ExecuteCmdlet() { if (Url == null) { ClientContext.Load(CurrentWeb, w => w.Url); ClientContext.ExecuteQueryRetry(); Url = CurrentWeb.Url; } if (Parent.HasValue) { var parentNode = CurrentWeb.Navigation.GetNodeById(Parent.Value); ClientContext.Load(parentNode); ClientContext.ExecuteQueryRetry(); var addedNode = parentNode.Children.Add(new NavigationNodeCreationInformation() { Title = Title, Url = Url, IsExternal = External.IsPresent, AsLastNode = !First.IsPresent }); ClientContext.Load(addedNode); ClientContext.ExecuteQueryRetry(); WriteObject(addedNode); } else { NavigationNodeCollection nodeCollection = null; if (Location == NavigationType.SearchNav) { nodeCollection = CurrentWeb.LoadSearchNavigation(); } else if (Location == NavigationType.Footer) { nodeCollection = CurrentWeb.LoadFooterNavigation(); } else { nodeCollection = Location == NavigationType.QuickLaunch ? CurrentWeb.Navigation.QuickLaunch : CurrentWeb.Navigation.TopNavigationBar; ClientContext.Load(nodeCollection); } if (nodeCollection != null) { var addedNode = nodeCollection.Add(new NavigationNodeCreationInformation() { Title = Title, Url = Url, IsExternal = External.IsPresent, AsLastNode = !First.IsPresent }); ClientContext.Load(addedNode); ClientContext.ExecuteQueryRetry(); WriteObject(addedNode); } else { throw new Exception("Navigation Node Collection is null"); } #pragma warning restore CS0618 // Type or member is obsolete } }
protected override void ExecuteCmdlet() { if (ParameterSetName == ParameterSet_ALLBYLOCATION) { if (Tree.IsPresent) { NavigationNodeCollection navigationNodes = null; if (Location == NavigationType.SearchNav) { navigationNodes = CurrentWeb.Navigation.GetNodeById(1040).Children; } else if (Location == NavigationType.Footer) { navigationNodes = CurrentWeb.LoadFooterNavigation(); } else { navigationNodes = Location == NavigationType.QuickLaunch ? CurrentWeb.Navigation.QuickLaunch : CurrentWeb.Navigation.TopNavigationBar; } if (navigationNodes != null) { var nodesCollection = ClientContext.LoadQuery(navigationNodes); ClientContext.ExecuteQueryRetry(); WriteObject(GetTree(nodesCollection, 0)); } } else { NavigationNodeCollection nodes = null; switch (Location) { case NavigationType.QuickLaunch: { nodes = CurrentWeb.Navigation.QuickLaunch; break; } case NavigationType.TopNavigationBar: { nodes = CurrentWeb.Navigation.TopNavigationBar; break; } case NavigationType.SearchNav: { nodes = CurrentWeb.Navigation.GetNodeById(1040).Children; break; } case NavigationType.Footer: { nodes = CurrentWeb.LoadFooterNavigation(); break; } } if (nodes != null) { ClientContext.Load(nodes); ClientContext.ExecuteQueryRetry(); WriteObject(nodes, true); } } } if (ParameterSpecified(nameof(Id))) { var node = CurrentWeb.Navigation.GetNodeById(Id); ClientContext.Load(node); ClientContext.Load(node, n => n.Children.IncludeWithDefaultProperties()); ClientContext.ExecuteQueryRetry(); if (Tree.IsPresent) { WriteObject(GetTree(new List <NavigationNode>() { node }, 0)); } else { WriteObject(node); } } }