Add heading and link to SharePoint left navigation through powershell

Home | SharePoint Administration | Add heading and link to SharePoint left navigation through powershell

I was wondering whether there is a way to add the heading and link to the left navigation of a SharePoint site using Powershell script. It is feasible, here is the full workable script below:-

$web = Get-SPWeb "http://yourserver:9090/sites/SCO/"
$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)


function AddLeftNavHeading($HeadingName,$Link)
{


$CreateSPNavigationNode = [Microsoft.SharePoint.Publishing.Navigation.SPNavigationSiteMapNode]::CreateSPNavigationNode

$qlNav = $pubWeb.Navigation.CurrentNavigationNodes

$headingNode = $CreateSPNavigationNode.Invoke($HeadingName, $Link, [Microsoft.SharePoint.Publishing.NodeTypes]::Heading, $qlNav)

$web.Update()

}


function AddLeftNavLink($HeadingName,$DisplayName,$URL,$External)

{
Start-Sleep -Seconds 5

$qlNav1 = $web.Navigation.QuickLaunch

$qlNav1 | select Title, ID

$qlink = $qlNav1 | where {$_.Title -eq $HeadingName}

$linkNode = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode($DisplayName,$URL,$External)

$qlink.Children.AddAsLast($linkNode)

}

AddLeftNavHeading "Heading" "http://microsoft.com"
AddLeftNavLink "Heading" "Link" "http://hotmail.com" "True"

 Subscribe to my blog

Leave a Reply