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 :
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 !