Add or remove tab from Global Navigation
#input parameters
#in case of issues with displaying welcome page tab, we have to create link as external (set IsExternal property to true in constructor)
# New-Object Microsoft.SharePoint.Navigation.SPNavigationNode($nodeName, $nodeUrl, $true)
$url="https://td_sp_ui/sites/test5"
$nodeUrl="https://td_sp_ui/sites/test5/Helpdesk/SitePages/ContactUs.aspx"
$nodeName="Contact Us"
# check to ensure Microsoft.SharePoint.PowerShell is loaded
$snapin=Get-PSSnapin | Where-Object {
$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null)
{
Write-Host "Loading SharePoint Powershell Snapin"
Add-PSSnapin "Microsoft.SharePoint.Powershell"
}
$web = get-spweb $url
$node=$web.Navigation.TopNavigationBar
$node|select-object|format-table
$item=$node|where-object {$_.Title -eq $nodeName}
#create new link in Global Navigation, if doesn't exist
if($item -eq $null)
{
write-host "There is no " $nodeName " tab in Global Navigation Menu. Creating..."
$newNode = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode($nodeName, $nodeUrl)
$web.Navigation.TopNavigationBar.AddAsLast($newNode)
$newChild = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode("dieta", "/Pages/testPage.aspx")
if($newNode.Children.Count -eq 0)
{
$newNode.Children.AddAsFirst($newChild)
}
else
{
#Add new node after previous node
$newNode.Children.Add($newChild,$newNode.Children[$newNode.Children.Count-1])
}
write-host $nodeName " tab was succesfuly added to Global Navigation."
}
else
#delete link from Global Navigation, if exists
{
write-host $nodeName " tab already exist in Global Navigation Menu. Deleting..."
$item=$node|where-object {$_.Title -eq $nodeName}
$item.Delete()
write-host $nodeName " tab was succesfuly deleted from Global Navigation."
}
$web.dispose()