Add heading and link to SharePoint Global Navigation through Powershell

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

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



function AddHeading($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 AddLink($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)

}


AddHeading "Heading" "http://microsoft.com"
AddLink "Heading" "Link" "http://hotmail.com" "True"

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

 Subscribe to my blog