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

Create Content Sources in SharePoint 2010 using PowerShell

Article posted by Anavijai on 10/14/2011 | Views: 4547 | Category: SharePoint | Level: Intermediate | Points: 250 red flag


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

Introduction

In the previous article, we learnt Create a Content Source Scope Rule in SharePoint 2010 using PowerShell. In this article we will be seeing how to create Content Sources for Enterprise Search Service Application in SharePoint 2010 using PowerShell.

Automating the Content Source creation in SharePoint 2010

 

We can create Content Sources for Enterprise Search Service Application in SharePoint 2010 from Central Administration.

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

 

On the Quick Launch Menu, go to Crawling and then click on Content Sources.

 

 

 

 

You could be able to see the Content Sources. By clicking on New Content Source link we can create a new Content Source.

 

Another way is we can create the content sources for Search Service Application using SharePoint Object Model.

 

Here we will be seeing about automating the content source creation using powershell script.

 

 

Steps Involved:

 

1. Create the input xml file which contains the inputs for content source creation.
2. Create ps1 file which contains the script for content source creation.

 

CreateContentSources.xml

 

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

<ContentSources>

<SSAName>EnterPrise Search Service Application</SSAName>

<ContentSource Name="Sample1 SharePoint Sites" />

<ContentSource Name="Sample2 SharePoint Sites" />

<ContentSource Name="Sample3 SharePoint Sites" />

</ContentSources>


CreateContentSources.ps1

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

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

 #----------------Create New Content Source function---------------------------------------------

function CreateNewContentSource

{

$flag=0

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

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

$xmlData.ContentSources.ContentSource | ForEach-Object {

$contentSourceName=$_.Name

foreach ($availableContentSource in $ssaContent.ContentSources)

{

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

{

write-host -f Yellow $contentSourceName "content source already exists"

write-host -f Yellow Deleting $contentSourceName content source

$availablecontentSource.Delete()

write-host -f Green $contentSourceName content source is deleted successfully

write-host -f yellow Creating $contentSourceName

$ssaContent.ContentSources.Create([Microsoft.Office.Server.Search.Administration.SharePointContentSource], $contentSourceName)

write-host -f green $contentSourceName "content source is added successfully"

$Flag=1

break

}

}

if($Flag -eq 0)

{

write-host -f yellow Creating $contentSourceName

$ssaContent.ContentSources.Create([Microsoft.Office.Server.Search.Administration.SharePointContentSource], $contentSourceName)

write-host -f green $contentSourceName "content source is added successfully"

}

}

}

 

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

CreateNewContentSource

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

Output:

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

Thanks for reading.

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

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
>> Write Response - Respond to this post and get points
Related Posts

Adding Custom Asp.net pages into SharePoint using Layout Folder approach

This is my fourth series of SharePoint Quick Start FAQ. In this series the theme is WebPart , WebPart and WebPart.  So let us enjoy the WebPart bonanza.

Sharepoint sites may contain few webparts which exist in all its subsites commonly. This article is used to find the webpart and synchronize their stying using css styles instead of inline styling which needs lots of manual work even for a small change.

This is my third series of SharePoint Quick Start FAQ. We will cover page templates , page instances , WSS model , understand safe mode processing , deploy custom controls and understand WebParts. So let’s drink the SharePoint wine series by series, slowly , maintain the hangover and enjoy this great product.

In this article we will have look on Custom List of SharePoint 2010.

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/24/2013 12:04:54 AM