Freigeben über


Create a new Search Service Application in SharePoint 2013 using PowerShell

 

The search architecture in SharePoint 2013 has changed quite a bit when compared to SharePoint 2010. In fact the Search Service in SharePoint 2013 is completely overhauled. It is a combination of FAST Search and SharePoint Search components.

apxvsdik

As you can see the query and crawl topologies are merged into a single topology, simply called "Search topology". Provisioning of the search service application creates 4 databases:

  • SP2013_Enterprise_Search - This is a search administration database. It contains configuration and topology information
  • SP2013_Enterprise_Search_AnalyticsReportingStore - This database stores the result of usage analysis
  • SP2013_Enterprise_Search_CrawlStore - The crawl database contains detailed tracking and historical information about crawled items
  • SP2013_Enterprise_Search_LinksStore - Stores the information extracted by the content processing component and also stores click-through information

# Create a new Search Service Application in SharePoint 2013

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

# Settings
$IndexLocation = "C:\Data\Search15Index” #Location must be empty, will be deleted during the process!
$SearchAppPoolName = "Search App Pool"
$SearchAppPoolAccountName = "Contoso\administrator"
$SearchServerName = (Get-ChildItem env:computername).value
$SearchServiceName = "Search15"
$SearchServiceProxyName = "Search15 Proxy"
$DatabaseName = "Search15_ADminDB"
Write-Host -ForegroundColor Yellow "Checking if Search Application Pool exists"
$SPAppPool = Get-SPServiceApplicationPool -Identity $SearchAppPoolName -ErrorAction SilentlyContinue

if (!$SPAppPool)
{
    Write-Host -ForegroundColor Green "Creating Search Application Pool"
    $spAppPool = New-SPServiceApplicationPool -Name $SearchAppPoolName -Account $SearchAppPoolAccountName -Verbose
}

# Start Services search service instance
Write-host "Start Search Service instances...."
Start-SPEnterpriseSearchServiceInstance $SearchServerName -ErrorAction SilentlyContinue
Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $SearchServerName -ErrorAction SilentlyContinue

Write-Host -ForegroundColor Yellow "Checking if Search Service Application exists"
$ServiceApplication = Get-SPEnterpriseSearchServiceApplication -Identity $SearchServiceName -ErrorAction SilentlyContinue

if (!$ServiceApplication)
{
    Write-Host -ForegroundColor Green "Creating Search Service Application"
    $ServiceApplication = New-SPEnterpriseSearchServiceApplication -Partitioned -Name $SearchServiceName -ApplicationPool $spAppPool.Name 
-DatabaseName $DatabaseName
}

Write-Host -ForegroundColor Yellow "Checking if Search Service Application Proxy exists"
$Proxy = Get-SPEnterpriseSearchServiceApplicationProxy -Identity $SearchServiceProxyName -ErrorAction SilentlyContinue

if (!$Proxy)
{
    Write-Host -ForegroundColor Green "Creating Search Service Application Proxy"
    New-SPEnterpriseSearchServiceApplicationProxy -Partitioned -Name $SearchServiceProxyName -SearchApplication $ServiceApplication
}

$ServiceApplication.ActiveTopology
Write-Host $ServiceApplication.ActiveTopology

# Clone the default Topology (which is empty) and create a new one and then activate it
Write-Host "Configuring Search Component Topology...."
$clone = $ServiceApplication.ActiveTopology.Clone()
$SSI = Get-SPEnterpriseSearchServiceInstance -local
New-SPEnterpriseSearchAdminComponent –SearchTopology $clone -SearchServiceInstance $SSI
New-SPEnterpriseSearchContentProcessingComponent –SearchTopology $clone -SearchServiceInstance $SSI
New-SPEnterpriseSearchAnalyticsProcessingComponent –SearchTopology $clone -SearchServiceInstance $SSI
New-SPEnterpriseSearchCrawlComponent –SearchTopology $clone -SearchServiceInstance $SSI

Remove-Item -Recurse -Force -LiteralPath $IndexLocation -ErrorAction SilentlyContinue
mkdir -Path $IndexLocation -Force

New-SPEnterpriseSearchIndexComponent –SearchTopology $clone -SearchServiceInstance $SSI -RootDirectory $IndexLocation
New-SPEnterpriseSearchQueryProcessingComponent –SearchTopology $clone -SearchServiceInstance $SSI
$clone.Activate()

Write-host "Your search service application $SearchServiceName is now ready"

Update

To configure failover server(s) for Search DBs, use the following PowerShell:

Thanks to Marcel Jeanneau for sharing this!

#Admin Database
$ssa = Get-SPEnterpriseSearchServiceApplication “Search Service Application”
Set-SPEnterpriseSearchServiceApplication –Identity $ssa –FailoverDatabaseServer <failoverServerAlias\instance>

#Crawl Database
$CrawlDatabase0 = ([array]($ssa | Get-SPEnterpriseSearchCrawlDatabase))[0]
Set-SPEnterpriseSearchCrawlDatabase -Identity $CrawlDatabase0 -SearchApplication $ssa -FailoverDatabaseServer <failoverServerAlias\instance>

#Links Database
$LinksDatabase0 = ([array]($ssa | Get-SPEnterpriseSearchLinksDatabase))[0]
Set-SPEnterpriseSearchLinksDatabase -Identity $LinksDatabase0 -SearchApplication $ssa -FailoverDatabaseServer <failoverServerAlias\instance>

#Analytics database
$AnalyticsDB = Get-SPDatabase –Identity <id of database>
$AnalyticsDB.AddFailOverInstance(“failover alias\instance”)
$AnalyticsDB.Update()

 

See the following articles for information about Search Service Application in SharePoint 2013

Comments

  • Anonymous
    January 01, 2003
    You can always change the default content access account using the following command: $password = Read-Host –AsSecureString**********Set-SPEnterpriseSearchService -id "SSA name" –DefaultContentAccessAccountName Contosoaccount –DefaultContentAccessAccountPassword $password

  • Anonymous
    January 01, 2003
    Great script

  • Anonymous
    March 11, 2013
    I noticed that with this script the Farm account gets used as teh Default content access account even though the Pool account gets properly configure. Maybe it is something specific to my configuration, but I am pretty sure you don't want the Farm Application Pool account to be the default content access account. Also: I am guessing since the Default content access account is not a managed account, you probably don't want to use managed accounts if they are going to have scheduled password chanages. Any comments or thoughts on how to do this differently so that a different search account is used for the Default content access account would be greatly appreciated.

  • Anonymous
    August 30, 2013
    The comment has been removed

  • Anonymous
    September 11, 2013
    What is the error when the New-SPEnterpriseSearchAdminComponent command fails ?

  • Anonymous
    June 19, 2014
    The comment has been removed

  • Anonymous
    July 03, 2014
    The comment has been removed

  • Anonymous
    February 20, 2015
    Wonderful post however I was wondering if you could write a little more on this topic? I’d be very thankful if you could elaborate a little bit further. Thank you!
    http://staygreenacademy.com">SharePoint 2013 Training

  • Anonymous
    February 20, 2015
    I absolutely love your blog and find nearly all of your post’s to be precisely what I’m looking for.
    http://khalil-kothia.com">SharePoint Freelancer

  • Anonymous
    March 01, 2015
    Great article ...Thanks for your great information, the contents are quiet interesting. I will be waiting for your next post.
    http://staygreenacademy.com">SharePoint Online Training

  • Anonymous
    April 06, 2015
    http://blogs.technet.com/b/praveenh/archive/2013/02/07/create-a-new-search-service-application-in-sharepoint-2013-using-powershell.aspx

  • Anonymous
    April 06, 2015
    https://media.licdn.com/mpr/mpr/shrink_500_500/p/5/005/027/2c2/13da3b3.jpg