SIGN UP MEMBER LOGIN:    
ARTICLE

Create Scopes in SharePoint 2010 using PowerShell

Posted by Vijai Anand Articles | SharePoint September 12, 2011
In this article we will be seeing how to create Scopes in a SharePoint 2010 Enterprise Search Service Application using PowerShell.
Reader Level:

In this article we will be seeing how to create Scopes in a SharePoint 2010 Enterprise Search Service Application using PowerShell.

Automating the Scopes creation in SharePoint 2010

We can create Scopes in a SharePoint 2010 Enterprise Search Service Application from Central Administration.

Go to Central Administration => Application Management => Manage Service Applications => Enterprise Search Service Application.

Create Scopes in SharePoint 2010 using PowerShell

On the Quick Launch Menu, go to Queries and Results then click on Scopes.

Create Scopes in SharePoint 2010 using PowerShell

You should be able to see the Scopes. By clicking on New Scope link we can create a new Scope.

Another way is we can create the Search Scopes in SharePoint 2010 using SharePoint Object Model.

Here we will be seeing about automating the Scopes creation using a powershell script.

Steps Involved:

  1. Create the input XML file which contains the inputs for Scope creation.
  2. Create ps1 file which contains the script for scope creation.

CreateScopes.xml

<?xml version="1.0" encoding="utf-8" ?>
<Scopes>
  <
SSAName>EnterPrise Search Service Application</SSAName>
  <Scope Name="Sample1" Description="Sample1 Scope" />
  <Scope Name="Sample2" Description="Sample2 Scope" />
  <Scope Name="Sample3" Description="Sample3 Scope" />
</Scopes>

CreateScopes.ps1

 #----------------Get the xml file---------------------------------------------------------------

 [xml]$xmlData=Get-Content "C:\Users\Desktop\ContentSources\CreateScopes.xml"

 #----------------Create New Scope function---------------------------------------------

 Function CreateNewScope()
{    
       
$ssa=Get-SPEnterPriseSearchServiceApplication -Identity $xmlData.SSAName
       
$scopeCollection=Get-SPEnterpriseSearchQueryScope  -SearchApplication $ssa
       $xmlData.Scopes.Scope | ForEach-Object {
             
$newScopeName=$_.Name 
             
$newScopeDescription=$_.Description
             
$scope=Get-SPEnterpriseSearchQueryScope -Identity $newScopeName -SearchApplication $ssa
             
if($scope -eq $null)
             {
                   
write-host -f Magenta Creating scope $_.scope
                   New-SPEnterpriseSearchQueryScope -Name
$newScopeName -Description $newScopeDescription -SearchApplication $ssa -DisplayInAdminUI $true                              
                   
write-host -f Green $newscope.Name is created successfully
             }
             
else
             {
                   
write-host -f yellow $newScopeName scope already exists
                    write-host -f yellow Deleting $newScopeName scope
                    Remove-SPEnterpriseSearchQueryScope -Identity $newScopeName -SearchApplication $ssa -confirm:0
                    
write-host -f green $newScopeName scope is deleted successfully
                    write-host -f Magenta Creating $newScopeName scope
                    New-SPEnterpriseSearchQueryScope -Name
$newScopeName -Description  $newScopeDescription -SearchApplication $ssa -DisplayInAdminUI $true                                 
                   
write-host -f green  $newScopeName scope is successfully created
             } 
       }
}
 
#----------------Calling the function---------------------------------------------

CreateNewScope

Run the Script:

  1. Go to Start.

  2. Click on All Programs.

  3. Click on Microsoft SharePoint 2010 Products and then click on SharePoint 2010 Management Shell.

  4. Run the C:\Users\Desktop\ContentSources\CreateScopes.ps1

Output:

Create Scopes in SharePoint 2010 using PowerShell

And in the Central Administration you could see the newly added Scopes as shown in the following

Create Scopes in SharePoint 2010 using PowerShell


  

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Become a Sponsor