1

We created a search center in our intranet. We configured the root web of each site collection so that the search uses the search center. We also configured search navigation.

Then we made a PowerShell script to update all the subsites (except the root) of each site collection so that each subsite :

  • use the search center
  • use the same results page settings as its parent
  • use the same search navigation as its parent

After executing the script, the search settings were not applied on the subsites. When we checked the "Search Settings" page, the option were correctly checked :

Search Settings on subsites

But, when we click on the "OK" button on the page, the settings are applied. I don't understand.

Here's the script used :

$SPWebApp = Get-SPWebApplication "xxxx" 
foreach ($SPSite in $SPWebApp.Sites)
{
    $rootWeb = Get-SPWeb $SPSite.Url
    foreach ($subsite in $rootWeb.Site.AllWebs)
    {
        $nbSite = $nbSite + 1
        if($subsite.id -eq $SPSite.RootWeb.id){
            $count = $rootWeb.Navigation.SearchNav.Count

            # use a classic for loop to iterate through the collection
            for($i = 0; $i -lt $count; $i++) {
                # delete the 0th node
                $navItem = $rootWeb.Navigation.SearchNav[0];
                $node = $rootWeb.Navigation.SearchNav.Delete($navItem)
            }
            $node = new-object -TypeName "Microsoft.SharePoint.Navigation.SPNavigationNode" -ArgumentList "Ce site", "$($SPWebApp.Url)sites/CentreDeRecherche/Pages/results.aspx", $true
            $node = $rootWeb.Navigation.SearchNav.AddAsLast($node)
            $node = new-object -TypeName "Microsoft.SharePoint.Navigation.SPNavigationNode" -ArgumentList "Personnes", "$($SPWebApp.Url)sites/CentreDeRecherche/Pages/peopleresults.aspx", $true
            $node = $rootWeb.Navigation.SearchNav.AddAsLast($node)
            $node = new-object -TypeName "Microsoft.SharePoint.Navigation.SPNavigationNode" -ArgumentList "Conversations", "$($SPWebApp.Url)sites/CentreDeRecherche/Pages/conversationresults.aspx ", $true
            $node = $rootWeb.Navigation.SearchNav.AddAsLast($node)
        }
        else
        {
            #SubSite settings
            $subsite.AllProperties[“SRCH_VERT_SET_WEB”] =  ‘{"Inherit":true}’
            $subsite.AllProperties[“SRCH_ENH_FTR_URL_WEB”] = "$($SPWebApp.Url)sites/CentreDeRecherche/Pages"
            $subsite.AllProperties[“SRCH_SB_SET_WEB”] =  ‘{"Inherit":true,"ResultsPageAddress":"/sites/CentreDeRecherche/Pages/results.aspx","ShowNavigation":true}’
        }
        $subsite.Update();
    }
    $rootWeb.Update();
}

Thanks for your help !

1 Answer 1

0

Maybe this is helpful even though it does not exactly 100% address your issue.

We use the following script to go through all sites and make changes to redirect users to our search center:

    Add-PSSnapin Microsoft.SharePoint.PowerShell
param(
     [string]$webAppUrl,
     [string]$searchCenterUrl,
     [string]$resultsPage
 )

 function Set-Search-Settings($site)
 {
     Write-Host "Set search settings on site" $site.Url -foregroundcolor red
     $web = Get-SPWeb $site.Url        
     $web.AllProperties["SRCH_SB_SET_SITE"] = 
 '{"Inherit":false,"ResultsPageAddress":"' + $resultsPage + '","ShowNavigation":false}' 
     $web.AllProperties["SRCH_ENH_FTR_URL_SITE"] = $searchCenterUrl
     $web.Update()
     Write-Host "    Search settings were successfully set"  -foregroundcolor green
 }

 if (-not $webAppUrl)
 {
     Write-Host "Specify web app url in webAppUrl parameter"  -foregroundcolor red
     return
 }

 if (-not $searchCenterUrl)
 {
     Write-Host "Specify web app url in searchCenterUrl parameter"  -foregroundcolor red
    return
 }

 if (-not $resultsPage)
 {
     Write-Host "Specify web app url in resultsPage parameter" -foregroundcolor red
     return
 }

 Start-Transcript -Path "output.log" -Append -Force -Confirm:$false

 $wa = Get-SPWebApplication $webAppUrl
 $wa.Sites | ForEach-Object { Set-Search-Settings $_ }

 Stop-Transcript

Save it as e.g. "SetSearchCenter.ps1" and run the following:

.\SetSearchCenter.ps1 -webAppUrl http://YourIntranet.com -searchCenterUrl http://YourIntranet.com/search/Pages -resultsPage "{SearchCenterURL}/results.aspx"

In our farm it now takes ~2 minutes for the settings to take effect on every site.

Also: I do not take credit for this script but I can't remember where I got it from.

Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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