SharePoint 2013 Create Search Service Application with PowerShell

This guide shows you how to create a SharePoint 2013 Search Service Application using PowerShell and how this process differs from creating a SharePoint 2010 Search Service Application using PowerShell.

Please note this is work in progress. This post is part of SharePoint 2013 resource page.

Search Service Application

SharePoint 2013 Search Service Application created with PowerShell.

PowerShell to create Search

Here are the steps I used to create a new Search Service Application in SharePoint 2013 using PowerShell:

  1. Create a new Service Application:
    $ServiceApplication = New-SPEnterpriseSearchServiceApplication 
    -Name "Search SA"
    -ApplicationPool $spAppPoolName
    -DatabaseServer "SERVERNAME"
    -DatabaseName "Database Name"
  2. Create a new Service Application Proxy:
    -Name "Search SA Proxy" -SearchApplication "Search SA"
    Note: The name of the search service application is sufficient for the parameter 'SearchApplication' but might change.

  3. Get the Search Instance. The instance is used to associate new Search Components (crawl, query, admin…) create later with the instance itself: 
    $searchInstance = Get-SPEnterpriseSearchServiceInstance -local 
  4. Get the active Search Topology. This is used to monitor the state of the old search topology which becomes inactive if the new one gets active:
    $InitialSearchTopology = $ServiceApplication | Get-SPEnterpriseSearchTopology 
    Note: In SharePoint 2010 Get-SPEnterpriseSearchCrawlTopology was used instead.
  5. Create a new Search Topology. New Search Components  (crawl, query, admin…) have to be associated with a search instance and a search topology.
     $SearchTopology = $ServiceApplication | New-SPEnterpriseSearchTopology 
  6. Create Administration Component and Processing Components. Here you need the search instance and new search topology from above:
    -SearchTopology $SearchTopology -SearchServiceInstance $searchInstance
    -SearchTopology $SearchTopology -SearchServiceInstance $searchInstance
    -SearchTopology $SearchTopology -SearchServiceInstance $searchInstance
    -SearchTopology $SearchTopology -SearchServiceInstance $searchInstance
    Note: Looks like the following statement doesn't work to create a search admin component:
    $ssa | get-SPEnterpriseSearchAdministrationComponent | set-SPEnterpriseSearchAdministrationComponent -SearchServiceInstance $searchInstance
    $ssa | Get-SPEnterpriseSearchAdministrationComponent
  7. Create a new Crawl Component:
    -SearchTopology $SearchTopology -SearchServiceInstance $searchInstance
  8. Create a new Index (Query) Component:
    New-SPEnterpriseSearchIndexComponent -SearchTopology $SearchTopology 
    -SearchServiceInstance $searchInstance -RootDirectory $IndexLocation
    • In SharePoint 2010 the PowerShell cmdlet was New-SPEnterpriseSearchQueryComponent.
    • The ‘RootDirectory’ property requires and existing AND empty folder like "C:\Program Files\Microsoft Office Servers\15.0\Data\Office Server\Applications\Index". If not existing OR not empty it fails.
  9. Activated the new Search Topology and deactivate the old one:
    $SearchTopology | Set-SPEnterpriseSearchTopology 
    • I encountered that activating the topology requires all components created first, otherwise you get an error e.g. 'Set-SPEnterpriseSearchTopology : At least one index partition does not contain any components.'
    • In SharePoint 2010 the cmdlet was Set-SPEnterpriseSearchQueryTopology.
    • The old topology wasn't set to inactive for 15 minutes although TechNet says: "This cmdlet enables the search topology with the given identity, marking the currently active search topology as inactive." So maybe I didn't allocated enough system resources (especially I was short of RAM) or it takes more time.
  10. Remove the old Search Topology:
    do { Write-Host -NoNewline .;Start-Sleep 6;} 
    while ($InitialSearchTopology.State -ne "Inactive") $InitialSearchTopology | Remove-SPEnterpriseSearchTopology -Confirm:$false
    Note: This needs more investigation as written one step above. Btw: I got this statement from Todd Klindt as well as an adapted one from Spencer Harbar.
  11. Get the finished PowerShell script that is part of my book if you don't want to do it manually.

Please leave a comment if you have some tips.