What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 22292 |  Welcome, Guest!   Register  Login
Home > Articles > SharePoint > Create a Content Source Scope Rule in SharePoint 2010 using PowerShell

Create a Content Source Scope Rule in SharePoint 2010 using PowerShell

1 vote(s)
Rating: 4 out of 5
Article posted by Anavijai on 10/13/2011 | Views: 5216 | Category: SharePoint | Level: Intermediate | Points: 250 red flag


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

Introduction

In the previous article, we learnt Business Data List Web Part in SharePoint 2010. In this article we will be seeing how to create a Content Source Scope Rule in SharePoint 2010 Enterprise Search Service Application using PowerShell.

Content Source Scope Rule creation in SharePoint 2010

We can create Content Source Scope Rule 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.

Click on the Scope to which Scope Rule has to be added.

Click on Add New Rule link to add the new scope rule.

In the Scope Rule Type section, select Content Source.

In the Content Sources section, select the Content Source that has to be added to the scope rule.

Click on Ok.

Automating the Content Source Scope Rule creation in SharePoint 2010

Here we will be seeing about automating the Content Source Scope Rule creation using powershell script.

Steps Involved:

1. Create the input xml file which contains the inputs for Content Source Scope Rule creation.
2. Create ps1 file which contains the script for Content Source Scope Rule creation.

CreateContentSourceScopeRules.xml

<?xml version="1.0" encoding="utf-8" ?>

<ScopeRules>

<SSAName>AZ ESP EnterPrise Search Service Application</SSAName>

<ScopeURL>http://ukslazspddev06:8080/</ScopeURL>

<Rule ScopeName="Sample1" ContentSourceName="Sample1 SharePoint Sites" />

<Rule ScopeName="Sample2" ContentSourceName="Sample2 SharePoint Sites" />

<Rule ScopeName="Sample3" ContentSourceName="Sample3 SharePoint Sites" />

</ScopeRules>


CreateContentSourceScopeRules.ps1


 #----------------Get the xml file---------------------------------------------------------------
 
 [xml]$xmlData=Get-Content "C:\Users\Desktop\ContentSources\CreateContentSourceScopeRules.xml"
 
 
 #----------------Create Content Source Scope Rule function---------------------------------------------

Function CreateContentSourceScopeRule()

{

$flag=0

$ssa=Get-SPEnterPriseSearchServiceApplication -Identity $xmlData.SSAName

$ssaContent = new-object Microsoft.Office.Server.Search.Administration.Content($ssa)

$scopeCollection=Get-SPEnterpriseSearchQueryScope -SearchApplication $ssa

$xmlData.ScopeRules.Rule | ForEach-Object {

$ScopeName=$_.ScopeName

$contentSourceName=$_.ContentSourceName

$scope=Get-SPEnterpriseSearchQueryScope -SearchApplication $ssa | Where-Object {$_.Name -eq $ScopeName}

if($scope -ne $null)

{

foreach ($availableContentSource in $ssaContent.ContentSources)

{

if ($availablecontentSource.Name.ToString() -eq $contentSourceName)

{

$flag=1

break

}

}

if($flag -eq 1)

{

$ScopeRules=Get-SPEnterpriseSearchQueryScopeRule -Scope $scope | Where-Object {$_.Value -eq $contentSourceName}

if($scopeRuleFlag -ne $null)

{

write-host -f Yellow "Can't add or modify scope rule. A rule with the same parameters already exists in this scope"

}

else

{

write-host -f Magenta Creating Content Source Scope Rule

New-SPEnterpriseSearchQueryScopeRule -RuleType PropertyQuery -ManagedProperty ContentSource -PropertyValue $contentSourceName -FilterBehavior Include -URL $xmldata.ScopeRules.ScopeURL -scope $scope -SearchApplication $ssa

write-host -f Green Content Source Scope Rule is created successfully to $ScopeName scope

}

}

else

{

write-host -f Yellow $contentSourceName content source does not exists

}

}

else

{

write-host -f yellow $ScopeName scope does not exists

}

}

}

 #----------------Calling the function---------------------------------------------

 
 CreateContentSourceScopeRule

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\CreateContentSourceScopeRules.ps1

Output:

And in the Central Administration you could see the newly added Content Source Scope Rule as shown in the following

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

Thanks for reading. In the next article we shall learn Create Content Sources in SharePoint 2010 using PowerShell.

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Experience:2 year(s)
Home page:http://www.dotnetfunda.com
Member since:Sunday, May 22, 2011
Level:Starter
Status: [Member]
Biography:SharePoint Developer
 Responses
Posted by: Debal_saha@yahoo.com | Posted on: 17 Oct 2011 02:44:01 AM | Points: 25

HI,
This is very interesting article , but to be honest I want to say that I don't know what is sharepoint . How to do work , From where and what software to need install in my computer , I have VS2010, Can I learn sharepoint in it .

If you help me , so that i can study and understand sharepoint. Please also tell me why to need sharepoint ?
Is this means that to share important files, document reliable through it .

As a developer Should I learn SharePoint?


>> Write Response - Respond to this post and get points
Related Posts

In this article, we are going to learn how to display current login username in sharepoint using Javascript.

This article discusses various ways in which we can move a site collection to another content database

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

This post will help non developer IT professionals to add new File type icons in SharePoint like PDF which is not supported by SharePoint by default.

In this article we will be seeing how to customize SharePoint List Forms using InfoPath Forms.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/23/2013 2:44:23 PM