How To Configure Search Service Application Using PowerShell

In this article, I will guide you through the steps involved in provisioning Search Application along with the corresponding PowerShell Script

Here are the steps that we will explore in the upcoming section.





Though we can provision Search Application from Central Admin as well the purpose here is to demonstrate the use of PowerShell commands required to provision Search Application so that’s what we will do.

First, let’s go to Central Admin to ensure that no existing instance of Search Service Application has been provisioned earlier.

Under Application Management -> Click on “Manage Service Applications”.




Here, we can see what all Service Application Instances provisioned earlier and we can see there are none.




Now, launch SharePoint Management Shell to run the required PowerShell commands.




We will run the PowerShell commands in the following order to make sure each Sub component is provisioned as desired.

Step 1 - Provision Service Application Instance

In this step, we will first provision Search Service Application using the following cmdlet.

$sa = New-SPEnterpriseSearchServiceApplication -Name "Search Service Application" -DatabaseName "SearchDB" –ApplicationPool "SecurityTokenServiceApplicationPool"

Make sure Application Pool exists before you run this command else it will fail since this cmdlet won't add the Application Pool automatically.




Step 2 - Provision Application Proxy

Then we need to provision Application Proxy by using the following cmdlet referring the Service Application Instance provisioned in the previous step.

New-SPEnterpriseSearchServiceApplicationProxy -Name "Search Service Application Proxy" -SearchApplication $sa



Step 3 - Validate Service Instance


Next step is to validate that the Service Instance is online and to do so we can use the following cmdlet.

Get-SPEnterpriseSearchServiceInstance -local


Step 4 - Clone Topology

Next step is to clone the topology which is required in order to make any changes to the search topology in a search installation that has items in the search index

As per Microsoft recommendation, around this, you need to modify this new topology object, which is a clone of the active topology, by adding or removing search components. After you have made the changes to the clone topology object, you have to activate this clone to have this topology in action.

$clone = $sa.ActiveTopology.Clone()




Step 5 - Get Search Service Instance Server Name

This Server name is required in the upcoming steps so it is wise to make use of the following cmdlet to retrieve the server name.

Get-SPEnterpriseSearchServiceInstance| Select Server




Step 6 - Get Search Service Instance

Then we get a handle over the search service instance running on the respective server using the following cmdlet

$si = Get-SPEnterpriseSearchServiceInstance | ?{$_.Server -match "SP-2016-Dev"}

This reference object will be used in the upcoming steps




Step 7 - Provision Admin Component

Next step is to provision a new Admin Component for the given topology and search service instance using the following cmdlet. This cmdlet is using reference to search service instance we get in the earlier steps

New-SPEnterpriseSearchAdminComponent -SearchTopology $clone -SearchServiceInstance $si




Step 8 - Provision Processing Component

Next step is to provision new content processing component for the given topology and search service instance using the following cmdlet

New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $clone -SearchServiceInstance $si


Step 9 - Provision Analytics Component

Then we have to provision new analytics processing component for the given topology and search service instance using the following cmdlet

New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $clone -SearchServiceInstance $si




Step 10 - Provision Crawl Component

Then we have to provision a new crawl component for the given topology and search service instance using the following cmdlet

New-SPEnterpriseSearchCrawlComponent -SearchTopology $clone -SearchServiceInstance $si




Step 11 - Provision Index Component

Then we have to provision a new index component for the given topology and search service instance using the following cmdlet

New-SPEnterpriseSearchIndexComponent -SearchTopology $clone -SearchServiceInstance $si -IndexPartition 0 -RootDirectory C:\SearchIndex\


Specifies the root directory that will hold the index location for the new search index component. If you plan to isolate the index on dedicated discs in order to avoid I/O contention that may leads to performance degradation as it might be a risk that index filling up the OS disk and ruin the overall server performance.




Step 12 - Provision Query Component

And finally we have to provision new query processing component for the given topology and search service instance using the following cmdlet

New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $clone -SearchServiceInstance $si




Step 13 - Activate New Topology

Once all the components have been added to the new topology, activate it by using the following cmdlet.





Step 14 - Clean Inactive Topologies

Finally, we have to clean all the inactive topologies associated with a search service application. We can perform this clean by using the following the code using “Remove-SPEnterpriseSearchTopology” cmdlet.

foreach($tp in (Get-SPEnterpriseSearchTopology -SearchApplication $sa | ?{$_.State -eq "Inactive"})) { Remove-SPEnterpriseSearchTopology -Identity $tp -Confirm:$false }




Step 15 - Change Default Content Access Account

And, we can change the default content access account by using the following code.

$sa = Get-SPEnterpriseSearchServiceApplication $content = New-Object Microsoft.Office.Server.Search.Administration.Content($sa) $content.SetDefaultGatheringAccount("<Enter User Name>", (ConvertTo-SecureString "<Enter Password>" -AsPlainText -Force))




Now, it is time to validate if search service application has been provisioned correctly.

Go to Central Admin -> Manage Service Applications.

We can see a new Search Application has been provisioned successfully by clicking the Search Service Application Link.




And, we can see all the components are provisioned and running as expected.




Also, we can validate the SQL Databases that have been provisioned during creating new search service applications as shown in the following screenshots.




Hope you find it helpful.