Add or remove tab from Global Navigation

10/01/2012 19:27

 #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)

   $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
                    $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)
          $newChild =  New-Object Microsoft.SharePoint.Navigation.SPNavigationNode("dieta", "/Pages/testPage.aspx")
            if($newNode.Children.Count -eq 0)
                #Add new node after previous node
          write-host $nodeName " tab was succesfuly added to Global Navigation."
                     #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}
                          write-host $nodeName " tab was succesfuly deleted from Global Navigation."