How to configure a SharePoint 2013 Search Service Application using PowerShell


Introduction
SharePoint 2013 offers a lot of PowerShell cmdlets to administer and configure the service applications in a SharePoint farm. You can find a starting reference here.

To create the Search service application with PowerShell, unlike other such as UPS, MMS and SSS, is not enough to use a single cmdlet to create the service application, and another one to create its proxy, but it requires additional configuration steps.

When I started this task for a my customer I looked the web to find some solutions and I found a bit of confusion and a lot of people writing about different issues, so I decided to write this post to help other to accomplish this task.

Common Issues
Many people try to provision their search service application only by using the New-SPEnterpriseSearchServiceApplication and the New-SPEnterpriseSearchServiceApplicationProxy cmdlets with a script like this:

> $searchServiceApp = New-SPEnterpriseSearchServiceApplication -Name $SearchAppName -ApplicationPool $saAppPool -DatabaseServer $SearchDatabaseServer -DatabaseName $SearchDatabaseName

> $searchServiceAppProxy = New-SPEnterpriseSearchServiceApplicationProxy -name $SearchAppName -SearchApplication $searchServiceApp

If you try to do this, you surely encounter an error on the event log like this:



With the following details:



This is because is missing the “Usage and Helth Data Collection” components used by the Search.

In addition, if you try to go in the “Search Administration” page it shows the following error:



In the logs you should also find the error: “Content Plugin can not be initialized – list of CSS addresses is not set.”.

If you try to search the web for this error, the article that best matches is the following:

http://blogs.msdn.com/b/sambetts/archive/2013/08/28/sp2013-win2012-unable-to-retrieve-topology-component-health-states-this-may-be-because-the-admin-component-is-not-up-and-running.aspxbut in this case the solution does not apply.

This error, instead, is because the default search topology is not defined.

Solution
Let me make a step back. If you try to create a Search service application by using the Central Administration, you notice the page shows more steps and its completion require some time.



When the execution is completed you notice the following three components are created:



Now its time to check the documentation!

The following article on Technet describes how to create and configure a Search service application in SharePoint 2013: http://technet.microsoft.com/en-us/library/gg502597.aspx by using the “Central Administration”.

The “Step 4” references how to manage the search topology in SharePoint Server 2013. In particular I focus on the “Change the default search topology in SharePoint Server 2013” article: http://technet.microsoft.com/EN-US/library/jj862356.aspx.

The article talks about how to change the default search topology to a new one. But, if you don’t have a Search service application published, you don’t have a search topology activated. So we can use the same article to create the default search topology and, in addition, the search service application.

Step 1 – Specify and starts the servers you want to add search components
First things to do is to specify servers where you need to add search components and start search services. To do this, use the following command(s): 

> $hostA = Get-SPEnterpriseSearchServiceInstance -Identity “myserver1”
> #$hostB = Get-SPEnterpriseSearchServiceInstance -Identity “myserver2”
> #$hostC = Get-SPEnterpriseSearchServiceInstance -Identity “myserver3”
> #$hostD = Get-SPEnterpriseSearchServiceInstance -Identity “myserver4”

> Start-SPEnterpriseSearchServiceInstance -Identity $hostA
> #Start-SPEnterpriseSearchServiceInstance -Identity $hostB
> #Start-SPEnterpriseSearchServiceInstance -Identity $hostC> #Start-SPEnterpriseSearchServiceInstance -Identity $hostD

Note: if you are testing the solution in a single machine environment you can change the script deploying all search components on the host A. In this case comment out the cmdlets about hosts B,C and D.

Now, wait until all the search service instances are running:

> do {$serviceA = Get-SPEnterpriseSearchServiceInstance -Identity $hostA} until ($serviceA.Status -eq “Online”)
> #do {$serviceB = Get-SPEnterpriseSearchServiceInstance -Identity $hostB} until ($serviceB.Status -eq “Online”)
> #do {$serviceC = Get-SPEnterpriseSearchServiceInstance -Identity $hostC} until ($serviceC.Status -eq “Online”)
> #do {$serviceD = Get-SPEnterpriseSearchServiceInstance -Identity $hostD} until ($serviceD.Status -eq “Online”)

Step 2 – Create the Seach service application
At this time we can create the Search service application using the following command(s):

> $searchServiceApp = New-SPEnterpriseSearchServiceApplication -Name $SearchAppName -ApplicationPool $saAppPool -DatabaseServer $SearchDatabaseServer -DatabaseName $SearchDatabaseName

> $searchServiceAppProxy = New-SPEnterpriseSearchServiceApplicationProxy -name $SearchAppName -SearchApplication $searchServiceApp

Note: in this post I don’t provide details about how to create a SharePoint application pool or about how to register a SharePoint managed account. If you need it check the documentation about the following cmdlets: New-SPServiceApplicationPool, New-SPManagedAccount.

Step 3 – Create the Usage and Health Data Collection service application
In this step we create the “Usage and Health Data Collection” service application by using the following command(s):

> $usageApp = New-SPUsageApplication -Name $UsageAppName -DatabaseServer $UsageDatabaseServer -DatabaseName $UsageDatabaseName
> Set-SPUsageApplication $UsageAppName -EnableLogging:$true
> Get-SPDiagnosticsProvider | Set-SPDiagnosticsProvider -Enable:$true

Step 4 – Create a new Search topology
Create a new search topology and a reference to the new search topology by using the following command(s):

> $searchServiceApp = Get-SPEnterpriseSearchServiceApplication $SearchAppName
> $newTopology = New-SPEnterpriseSearchTopology -SearchApplication $ssa

Add the search components to the new search topology according the search topology you have defined, with the following command(s):

> New-SPEnterpriseSearchAdminComponent -SearchTopology $newTopology -SearchServiceInstance $hostA
> New-SPEnterpriseSearchCrawlComponent -SearchTopology $newTopology -SearchServiceInstance $hostA
> New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $hostA
> New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $hostA
> New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $hostA
> New-SPEnterpriseSearchIndexComponent -SearchTopology $newTopology -SearchServiceInstance $hostA -IndexPartition 0

Note: as mentioned before, in this example we are deploying all search component on a single machine, if your search topology require more roles you can use this cmdlets to create on each machine the required components.

Now, activate the new Search topology with the following command:

> Set-SPEnterpriseSearchTopology -Identity $newTopology

At the end you can verify that the new search topology is active and that all components of the new Search topology are running correctly running the following command(s):

> Get-SPEnterpriseSearchTopology -SearchApplication $searchServiceApp
> Get-SPEnterpriseSearchStatus -SearchApplication $searchServiceApp -Text

Summary
In summary, the provision of a search service application is more than execute two commands. Before to start read the documentation and plan which accounts do you needs and define which topology best fits your requirements.
I hope this post can help you to create more easly a PowerShell script to deploy your search service application accross your SharePoint farm.

The above scripts are provided for the purpose of illustration only and is not intended to be used “as is” in a production environment. 

Advertisements
Tagged with: , , ,
Posted in SharePoint
3 comments on “How to configure a SharePoint 2013 Search Service Application using PowerShell
  1. […] How to configure a SharePoint 2013 Search Service Application using PowerShell (gianespo.wordpress.com) […]

  2. […] How to configure a SharePoint 2013 Search Service Application using PowerShell (gianespo.wordpress.com) […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: