Note for myself again.
I wanted to create search scope which returned results from a specific area in my SharePoint site collection. I also wanted this scope to be available in the site collection's "Scopes drop down".
This code did the trick
$createdScope = New-SPEnterpriseSearchQueryScope -Name "Specific area" -Description "Project sites" -SearchApplication $searchapp -DisplayInAdminUI $true $rule = New-SPEnterpriseSearchQueryScopeRule -RuleType "Url" -Url "http://portal" -MatchingString "http://portal/SpecificArea" -FilterBehavior "Require" -UrlScopeRuleType "Folder" -scope $createdScope $Site = Get-SPSite -Identity http://portal $searchContext = [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($Site) $scopes = new-Object Microsoft.Office.Server.Search.Administration.Scopes($searchContext) $displayGroup = $scopes.GetDisplayGroup("http://portal", "Search Dropdown") $displayGroup.Add($scopes.GetSharedScope("Specific area")) $displayGroup.Update()
This script was created based on the following posts so thanks the authors for pointing me in the right direction:
http://social.technet.microsoft.com/Forums/en-US/sharepointadminprevious/thread/6159b4b5-ec8a-4184-b5e8-1a226eff1cee/
http://onlinecoder.blogspot.co.uk/2012/12/powershell-script-to-create-search.html
I wanted to create search scope which returned results from a specific area in my SharePoint site collection. I also wanted this scope to be available in the site collection's "Scopes drop down".
This code did the trick
$createdScope = New-SPEnterpriseSearchQueryScope -Name "Specific area" -Description "Project sites" -SearchApplication $searchapp -DisplayInAdminUI $true $rule = New-SPEnterpriseSearchQueryScopeRule -RuleType "Url" -Url "http://portal" -MatchingString "http://portal/SpecificArea" -FilterBehavior "Require" -UrlScopeRuleType "Folder" -scope $createdScope $Site = Get-SPSite -Identity http://portal $searchContext = [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($Site) $scopes = new-Object Microsoft.Office.Server.Search.Administration.Scopes($searchContext) $displayGroup = $scopes.GetDisplayGroup("http://portal", "Search Dropdown") $displayGroup.Add($scopes.GetSharedScope("Specific area")) $displayGroup.Update()
This script was created based on the following posts so thanks the authors for pointing me in the right direction:
http://social.technet.microsoft.com/Forums/en-US/sharepointadminprevious/thread/6159b4b5-ec8a-4184-b5e8-1a226eff1cee/
http://onlinecoder.blogspot.co.uk/2012/12/powershell-script-to-create-search.html