3

I am creating a top nav hierarchy using Powershell. I can create the first level nodes easily enough, but second level nodes nevver get created and I get no errors from the script. Here is an example:

$web = get-spweb https://www.nga.dev
$node1 = New-Object         Microsoft.SharePoint.Navigation.SPNavigationNode("Products", "/Info/Pages/Content/ContentCatalog.aspx")
$web.Navigation.TopNavigationBar.AddAsFirst($node1)

$node2 = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode("Services", "/Info/Pages/Content/ServiceCatalog.aspx")
$web.Navigation.TopNavigationBar.Add($node2,$node1)

$node3 = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode("Missions", "/")
$web.Navigation.TopNavigationBar.Add($node3,$node2)

$subNode = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode("IA Missions","/")
$node3.Children.AddAsLast($subNode)
$node3.Update()
$subNode = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode("Other Missions","/")
$node3.Children.AddAsLast($subNode)
$node3.Update()
$web.Update()

I also notice that I need a valid URL in order for the node to show inthe top nav bar. Is this normal?

3

Use the CreateSPNavigationNode method and you can pass in the collection directly:

$subNode = [Microsoft.SharePoint.Publishing.Navigation.SPNavigationSiteMapNode]::CreateSPNavigationNode("IA Missions","/",[Microsoft.SharePoint.Publishing.NodeTypes.AuthoredLinkPlain], $node3.Children)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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