Skip to content

Instantly share code, notes, and snippets.

@ishajain
Created March 30, 2014 23:42
Show Gist options
  • Select an option

  • Save ishajain/9881921 to your computer and use it in GitHub Desktop.

Select an option

Save ishajain/9881921 to your computer and use it in GitHub Desktop.
$resultSourceID=$resultSource.ID
$resultSourceLevel="SPSite"
$webURL =$web.Url + "/searchcentre"
$web=Get-SPWeb $webURL
$pageUrl="$webURL/Pages/results.aspx?k=test"
$page=$web.lists["Pages"].Items | ? {$_.Name -eq "results.aspx"}
$page.File.CheckOut();
$webpartmanager=$web.GetLimitedWebPartManager($pageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
$webpart = $webpartmanager.WebParts | ? { $_.Title -eq 'Search Results' }
$dataProvider = ConvertFrom-Json $webpart.DataProviderJSON
$dataProvider.SourceID=$resultSourceID
$dataProvider.SourceLevel=$resultSourceLevel
$dataProvider.SourceName=$resultSourceName
$webpart.DataProviderJSON = ConvertTo-Json $dataProvider -Compress
$webpartmanager.SaveChanges($webpart)
$page.File.CheckIn("Changed the Result Source")
$page.File.Publish("Changed the Result Source")
Write-Host "Site Collection scope for the search results in the Search Results webpart is set to 'MyResultSource' successfully" -ForegroundColor green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment