Maybe you’re still kicking the tires on SharePoint 2013 installing it for the first time. Maybe you’re in the throws of planning your migration. Maybe you’re a consultant who’s been stuck on a SharePoint 2010 project for the last 18 months. Either way, we all have to face the music sooner or later and upgrade to SharePoint 2013. When you do, you’ll have to setup a Search Service. It’s not as bad as you’d think. And if you have at least 3 servers in your farm (1 app and 2 WFEs) then this script will work for you. Without further delay:
#Config Section $APP1 = "App1" $WFE1 = "WFE1" $WFE2 = "WFE1" $SearchAppPoolName = "SearchServiceAppPool" $SearchAppPoolAccountName = "domainSearchSvc" $SearchServiceName = "SharePoint Search Service" $SearchServiceProxyName = "SharePoint Search Service Proxy" $DatabaseServer = "DBserver" $DatabaseName = "SP_Search_AdminDB" #Create a Search Service Application Pool $spAppPool = New-SPServiceApplicationPool -Name $SearchAppPoolName -Account $SearchAppPoolAccountName -Verbose #Start Search Service Instance on all Application Server Start-SPEnterpriseSearchServiceInstance $App1 -ErrorAction SilentlyContinue Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $App1 -ErrorAction SilentlyContinue #Start Search Service Instance on WFEs Start-SPEnterpriseSearchServiceInstance $WFE1 -ErrorAction SilentlyContinue Start-SPEnterpriseSearchServiceInstance $WFE2 -ErrorAction SilentlyContinue #Create Search Service Application $ServiceApplication = New-SPEnterpriseSearchServiceApplication -Partitioned -Name $SearchServiceName -ApplicationPool $spAppPool.Name -DatabaseServer $DatabaseServer -DatabaseName $DatabaseName #Create Search Service Proxy New-SPEnterpriseSearchServiceApplicationProxy -Partitioned -Name $SearchServiceProxyName -SearchApplication $ServiceApplication $clone = $ServiceApplication.ActiveTopology.Clone() #Set variables for component creation $App1SSI = Get-SPEnterpriseSearchServiceInstance -Identity $App1 $WFE1SSI = Get-SPEnterpriseSearchServiceInstance -Identity $WFE1 $WFE2SSI = Get-SPEnterpriseSearchServiceInstance -Identity $WFE2 #Create Admin component New-SPEnterpriseSearchAdminComponent –SearchTopology $clone -SearchServiceInstance $App1SSI #Create Processing component New-SPEnterpriseSearchContentProcessingComponent –SearchTopology $clone -SearchServiceInstance $App1SSI #Create Analytics Processing component New-SPEnterpriseSearchAnalyticsProcessingComponent –SearchTopology $clone -SearchServiceInstance $App1SSI #Create Crawl component New-SPEnterpriseSearchCrawlComponent –SearchTopology $clone -SearchServiceInstance $App1SSI #Create query processing component New-SPEnterpriseSearchQueryProcessingComponent –SearchTopology $clone -SearchServiceInstance $App1SSI #Set the primary and replica index location; ensure these drives and folders exist on application servers $PrimaryIndexLocation = "C:SPSearch" $ReplicaIndexLocation = "C:SPSearchReplica" #We need two index partitions and replicas for each partition. Follow the sequence. New-SPEnterpriseSearchIndexComponent –SearchTopology $clone -SearchServiceInstance $WFE1SSI -RootDirectory $PrimaryIndexLocation -IndexPartition 0 New-SPEnterpriseSearchIndexComponent –SearchTopology $clone -SearchServiceInstance $WFE2SSI -RootDirectory $ReplicaIndexLocation -IndexPartition 0 New-SPEnterpriseSearchIndexComponent –SearchTopology $clone -SearchServiceInstance $WFE1SSI -RootDirectory $PrimaryIndexLocation -IndexPartition 1 New-SPEnterpriseSearchIndexComponent –SearchTopology $clone -SearchServiceInstance $WFE2SSI -RootDirectory $ReplicaIndexLocation -IndexPartition 1 $clone.Activate() #Verify Search Topology $ssa = Get-SPEnterpriseSearchServiceApplication Get-SPEnterpriseSearchTopology -Active -SearchApplication $ssa
This script is actually pretty basic. 90% of the services end up on your App box, while the Index partitions live on your WFEs. You could provision the service on one box or any combination you see fit. That’s the beauty of this model. For me, I like having the Index partition closest to where people will be searching (i.e. the WFEs).
The script should take anywhere from 10-30 minutes to run, maybe longer depending on your hardware. Once done, navigate to your Search Service in Central Admin and this is what you should see in the Search Topology.
Most important thing to remember when using this script is to create the C:SPSearch and C:SPSearchReplica directories on your WFEs PRIOR to running this script. The script will fail if you don’t do this and it’s a pain to cleanup after so create the directories first. I’ll probably write in a check to see if the directories exist – and if they don’t go, ahead and create them – next time I run this script when setting up an environment.