This script will synchronize the search center navigation links with the specified config file.  Existing links with the same title will be update and any links not defined in the config file will be deleted.

 

PowerShell
Edit|Remove
<# 
.SYNOPSIS 
    Initialize SP search navigation tabs based on XML config file 
.DESCRIPTION 
    This script will synchronize the search center navigation links 
    with the specified config file.  Existing links with the same 
    title will be update and any links not defined in the config  
    file will be deleted. 
.PARAMETER ConfigFile 
    Specifies the location of the config file containing the navigation items. 
.PARAMETER GenerateConfigFile 
    Output a sample configuration file 
.LINK  
    http://gallery.technet.microsoft.com/scriptcenter/Scripted-update-of-the-595d03a4  
.NOTES 
    File Name : Initialize-SPSearchNavs.ps1 
    Author    : Matthew King <matthew.king@microsoft.com> 
#> 
[CmdletBinding(DefaultParameterSetName="Run")] 
param([Parameter(Mandatory=$true, ParameterSetName="Run")] 
      [string]$ConfigFile, 
      [Parameter(Mandatory=$true, ParameterSetName="GenConfig")] 
      [switch]$GenerateConfigFile 
      ) 
 
if ($GenerateConfigFile) { 
    @" 
<Navs SiteUrl="https://servername/search" > 
  <Nav title="Everything" url="/Pages/results.aspx" /> 
  <Nav title="Intranet" url="/Pages/intranetresults.aspx" /> 
  <Nav title="E-mail" url="/pages/emailresults.aspx" /> 
  <Nav title="My Docs"  url="/pages/mydocsresults.aspx" /> 
  <Nav title="SharePoint" url="/pages/sharepointresults.aspx" /> 
</Navs> 
"@ 
    exit(0) 
} 
 
if (-not (Test-Path $ConfigFile)) { 
    Write-Error "Couldn't find config file $ConfigFile" 
    return 
} 
 
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue  
 
function GetAttribute { 
    param($node$attr$def=$null, [switch]$required) 
    if (-not $node.HasAttribute($attr)) { 
        if ($required) { 
            throw "{0}/@{1} is required" -$node.get_Name(), $attr 
        } 
        return $def 
    } 
    return $node.GetAttribute($attr) 
} 
 
[xml]$xml = Get-Content $ConfigFile #| Replace-ProjectProperties 
if (-not $?) { exit(1) } 
 
$siteUrl = GetAttribute $xml.Navs SiteUrl -Required 
if (Test-Path Function:\Replace-Localhost) { 
    $siteUrl = Replace-Localhost $siteUrl 
} 
$spweb = Get-SPWeb $siteUrl -ErrorAction Stop 
 
Write-Host "Adding search nav links to $siteUrl" 
foreach ($node in $xml.Navs.Nav) { 
    $title = GetAttribute $node title -Required 
    $url = GetAttribute $node url -Required 
    write-host "  + Title='$title' Url='$url' " -NoNewline 
    $nav = $spweb.Navigation.SearchNav | ? { $_.title -eq $title } 
    if ($nav) { 
        if ($nav.url -eq $url) {  
            Write-Host unchanged 
            continue;  
        } 
        # Need to delete in order to change the url 
        $nav.delete() 
    } 
    Write-Host "Adding " -NoNewline 
    $nav = New-Object -TypeName Microsoft.SharePoint.Navigation.sPNavigationNode -ArgumentList ($title$url) 
    $spweb.Navigation.AddToSearchNav($nav| Out-Null 
    if (-not $?) { break } 
    Write-Host OK 
} 
 
# Figure out if any need to be deleted 
 
$new = $xml.Navs.Nav | % { GetAttribute $_ title } 
$old = $spweb.Navigation.SearchNav | % { $_.title } 
 
foreach ($title in $old | ? { -not ($new -contains $_) }) { 
    Write-Host "  - Title='$title'" 
    $nav = $spweb.Navigation.SearchNav | ? { $_.title -eq $title } 
    $nav.Delete() 
}