Creating a Search Service Application and topology with PowerShell in SharePoint 2013 or 2016 – IN SAME APP POOL AS OTHER SERVICE APPLICATIONS

You can use this script to create a new search service application after you have removed your search service application.  WARNING: This creates the search service in an existing application pool named “SharePoint Hosted Services”.  Edit the $saAppPoolName, $serviceAppName, and $searchDBName to whatever you like making sure that the app pool already exists.  If it doesn’t exist, you should use the app pool that you run your other services, for example, excel services, visio, etc.

##Configure Farm Search Service Applications

## Create Enterprise Search Service (If Upgrading Use Existing Database Names) ##

## Based on scripts at http://www.harbar.net/articles/sp2013mt.aspx and http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=378 ##

## Thanks Todd and Spencer!##

## This should be run on the first server in your farm ##

## Get App Pool ##

$saAppPoolName = "SharePoint Hosted Services"

## Search Specifics, we are single server farm ##

$searchServerName = (Get-ChildItem env:computername).value

$serviceAppName = "Enterprise Search Services"

$searchDBName = "Search"


## Grab the Appplication Pool for Service Application Endpoint ##

$saAppPool = Get-SPServiceApplicationPool $saAppPoolName

## Start Search Service Instances ##

Write-Host "Starting Search Service Instances..."

Start-SPEnterpriseSearchServiceInstance $searchServerName

Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $searchServerName

## Create the Search Service Application and Proxy ##

Write-Host "Creating Search Service Application and Proxy..."

$searchServiceApp = New-SPEnterpriseSearchServiceApplication -Name $serviceAppName -ApplicationPool $saAppPoolName -DatabaseName $searchDBName

$searchProxy = New-SPEnterpriseSearchServiceApplicationProxy -Name "$serviceAppName Proxy" -SearchApplication $searchServiceApp

## Clone the default Topology (which is empty) and create a new one and then activate it ##

Write-Host "Configuring Search Component Topology..."

$appserv = Get-SPEnterpriseSearchServiceInstance -Identity $searchServerName


Get-SPEnterpriseSearchServiceInstance -Identity $appserv


$ssa = Get-SPEnterpriseSearchServiceApplication


$newTopology = New-SPEnterpriseSearchTopology -SearchApplication $ssa


New-SPEnterpriseSearchAdminComponent -SearchTopology $newTopology -SearchServiceInstance $appserv

New-SPEnterpriseSearchCrawlComponent -SearchTopology $newTopology -SearchServiceInstance $appserv

New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $appserv

New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $appserv

New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $appserv

New-SPEnterpriseSearchIndexComponent -SearchTopology $newTopology -SearchServiceInstance $appserv


Set-SPEnterpriseSearchTopology -Identity $newTopology



Write-Host "Search Service Application installation Complete!"