5

I found here a discussion about it:

https://social.technet.microsoft.com/Forums/office/en-US/fdb4c91c-0ecb-4815-a830-8b371aceeace/set-the-search-drop-down-in-all-sites-in-site-collection?forum=sharepointsearch

And a link to an powershell script.

http://sharepointloupe.net/search-navigation-dropdown-sp2013/

In general, I want to get on all sites in my sitecollection the same custom dropdown values. So I found a script here, which I am not able to use:

#region Parameters
param(
    [Parameter(Mandatory = $true)]
    [ValidateSet('site','webapplication')]
    [string]$Scope,

    [Parameter(Mandatory = $true)]
    [string]$URL,

    [bool]$RemoveExisting = $false
    )
if(-not($Scope)) { Throw "You must supply a value for -Scope. Examples -Scope site or -Scope webapplication" }
if(-not($URL)) { Throw "You must supply a value for -URL. Examples -URL http://mysharepoint.com" }
#endregion

#region Functions

#Save the search navigation nodes
$masterweb = Get-SPWeb $URL
$masternodes = $masterweb.Navigation.SearchNav

function Remove-SearchNav([string]$SiteURL)
{
    $site = Get-SPSite $SiteURL

     foreach ($web in $site.AllWebs) 
    {
        $SearchNav = $web.Navigation.SearchNav

        IF ($SearchNav -ne $NULL -and $web.url -ne $site.Rootweb.Url)
        {
            Write-Host -ForegroundColor Green "Removeing Search Navigation for" $web.url;
            foreach($node in $web.Navigation.SearchNav)
            {
                $web.Navigation.SearchNav.delete($node)
            }
        }
        $web.Dispose()
    }

    $site.Dispose()
    Write-Host -ForegroundColor Red "============================================="
}


function Update-SearchNav([string]$SiteURL)
{
 Write-Host -ForegroundColor Red "============================================="
 Write-Host -ForegroundColor Green "Updating Search Navigation at URL " -NoNewline;
 Write-Host -ForegroundColor Green $SiteURL

 remove-varable 
 $site = Get-SPSite $SiteURL

 foreach ($web in $site.AllWebs) 
 { 
  Write-Host -ForegroundColor Red "============================================="
  Write-Host -ForegroundColor Green "Updating Search Navigation at URL " -NoNewline;
  Write-Host -ForegroundColor Green $web.Url

  $SearchNav = $web.Navigation.SearchNav

  IF ($SearchNav -ne $NULL)
  {
   Write-Host -ForegroundColor Red "This Site Search Navigation Already containing values";
  }
  ELSE
  {
   foreach ($node in $masternodes)
   {
    Write-Host -ForegroundColor Green "Adding Search Navigation" $node.Title;
    $web.Navigation.SearchNav.AddAsLast($node)
   }
  }
   $web.Dispose()
 }
 $site.Dispose()
 Write-Host -ForegroundColor Red "============================================="
}

If ($Scope -eq "webApplication")
{
    $WebApplication = Get-SPWebapplication $URL

    if($RemoveExisting -eq $true)
    {
        Foreach ($Sites in $WebApplication.Sites)
        {
            Remove-SearchNav($Sites.URL)
        }
        Write-Host "Cleared the existing search navigation"
    }
    $site.Dispose();
    Foreach ($Sites in $WebApplication.Sites)
    {   
        Update-SearchNav($Sites.url.trim())
    }
}
elseif ($Scope -eq "site")
{
    if($RemoveExisting -eq $true)
    {
        Remove-SearchNav($URL)
        Write-Host "Cleared the existing search navigation"
    }
    Update-SearchNav($URL)
}

Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

But I can not figure out what to type in. It alyways throws the error:

The argument ... does not belong to the set "site,webpplication".

Can anyone help me out here? What parameters should I use? Where do I specify the dropdown values? Proberby an easy thing.

  • Can you add a question to your text rather than a link to another forum. – Matthew McDermott Aug 18 '16 at 20:49
  • updated my question. Thanks for the response @MatthewMcDermott – Patrick Aug 19 '16 at 6:07
  • Can you supply an example of what parameters you are passing? I have used this function and it works for me. – Matthew McDermott Aug 19 '16 at 11:24
  • The problem is, that I don't know which are the right parameters and where I should specify the dropdown values in the script. Could you be so kind and post a script with values as an answer? That would be awesome! – Patrick Aug 23 '16 at 13:52
  • You do not need to specify drop down values in the script. That needs to be done manually at the site collection root site Search settings .The script will just copy that into each sub site instead of you having to redo it for each subsite – Unnie Sep 8 '16 at 10:28
2
+50

Regarding the error you're seeing:

If you use [ValidateSet('site','webapplication')] for your Scope-argument, you can only call -Scope site or -Scope webapplication. If you use something different PowerShell will tell you by raising an exception ("The argument ... does not belong to the set ...")

Explaining the script:

(Be warned: My findings are from examining the script - I have not tested it!)

What I get from the script is that you have to set up the "root" seachnavigation manually and when you run this script it will then copy the seachnavigation to all sub-webs.

So, if you have a WebApplication http://my.sp/ with a SiteCollection on / (I think this is a requirement of the script) then you could set up the searchnavigation on http://my.sp/.

If you then call

.\This-Script -Scope webapplication -Url http://my.sp -RemoveExisting $true

The script will walk every site in the WebApplication and every web in every site and copy the searchnavigation from the rootweb of the site http://my.sp

If you instead call

.\This-Script -Scope site -Url http://my.sp -RemoveExisting $true

the script will walk each subweb of the site at http://my.sp and copy the searchnavigation from the rootweb

| improve this answer | |
  • Could you point out the actual values I need for "site" or "webapplication"? Is it possible to set a whole sitecollection (all sites and subsites) with the dropdown values? – Patrick Sep 5 '16 at 6:09
  • @Patrick: I updated the answer. – Nils Sep 5 '16 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.