Showing posts with label Content Sources using Power Shell commands. Show all posts
Showing posts with label Content Sources using Power Shell commands. Show all posts

Thursday, January 9, 2014

Creating content sources in SharePoint using PowerShell commands

We can create the content sources based on the content types as per the requirements. Content types for content sources might be SharePoint site or web or Files that associated with in SharePoint environment.
To create a content source based on a web content type we can use the following script,

$contentSourceName = “Name of the content source to be configured”;
$siteUrl = “URL of the Site”;
$ssa=Get-SPEnterPriseSearchServiceApplication -Identity $xmlData.SSAName;
$ssaContent = new-object Microsoft.Office.Server.Search.Administration.Content($ssa);
if($myType -eq “Web”){

$webContentSource=$ssaContent.ContentSources.Create([Microsoft.Office.Server.Search.Administration.WebContentSource], $contentSourceName);

$webContentSource.startAddresses.Add($siteUrl);
}

Here $myType is content type

To create a content source based on a SharePoint content type we can use the following script,

$contentSourceName = “Name of the content source to be configured”;
$siteUrl = “URL of the Site”;
$ssa=Get-SPEnterPriseSearchServiceApplication -Identity $xmlData.SSAName
$ssaContent = new-object Microsoft.Office.Server.Search.Administration.Content($ssa)
if($myType -eq “SharePoint”){

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

$sharepointContentSource.startAddresses.Add($siteUrl);
}

To create a content source based on a File content type we can use the following script,

$contentSourceName = “Name of the content source to be configured”;
$siteUrl = “URL of the Site”;
$ssa=Get-SPEnterPriseSearchServiceApplication -Identity $xmlData.SSAName
$ssaContent = new-object Microsoft.Office.Server.Search.Administration.Content($ssa)
if($myType -eq “File”){

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

$fileContentSource.startAddresses.Add($siteUrl);
}