Create Scopes in SharePoint 2010 using PowerShell

Anavijai
Posted by in SharePoint category on for Intermediate level | Points: 250 | Views : 6082 red flag
Rating: 4 out of 5  
 1 vote(s)

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

Introduction

In the previous article, we learnt Create InfoPath form in SharePoint 2010 .In this article we will be seeing how to create Scopes in SharePoint 2010 Enterprise Search Service Application using PowerShell

Automating the Scopes creation in SharePoint 2010

We can create Scopes in SharePoint 2010 Enterprise Search Service Application from Central Administration.
Go to Central Administration => Application Management => Manage Service Applications => Enterprise Search Service Application.

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

You could 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 Scopes in Search Service Application using SharePoint Object Model.

Here we will be seeing about automating the Scopes creation using 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:

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

Thanks for reading.

Hope this article was useful, keep reading my forthcoming article of this series.

Page copy protected against web site content infringement by Copyscape

About the Author

Anavijai
Full Name: Vijai Anand R
Member Level: Starter
Member Status: Member
Member Since: 5/22/2011 5:12:38 AM
Country: India
Vijai Anand.R
http://www.dotnetfunda.com
SharePoint Developer

Login to vote for this post.

Comments or Responses

Posted by: mareesnectar-12158 on: 1/3/2012 | Points: 25
your articles are so good.....

now i have one year experience in c#.net ,sql......
now i want to learn share point step by step....
please guide me...........
my mail id:marees.nectar@gmail.com
cell.No:09787357012
Thanks with Regards
M.Mareeswaran

Login to post response

Comment using Facebook(Author doesn't get notification)