Migrating a Search Service Application

If you ever have to migrate a search service application from one farm to the next.  Do two things:

 

  1. Make sure that the farm’s use the correct SQL client Alias (cliconfg.exe)
  2. Run this powershell after you have migrated the SQL database and attached it within SQL.  The database named Search, or Search Admin.  In otherwords, the search admin database needs to be backed up and restored onto the target farm SharePoint SQL instance, that is the db name parameter that must match.  In the example code below we have Prod_Search as the db name. You’ll need to modify that name to match your DB name in SQL.
Add-PSSnapin "Microsoft.SharePoint.PowerShell" 
 
$SPSearchPoolAccount = Get-SPManagedAccount "PROD-SP_SearchSvc" 
New-SPServiceApplicationPool -Name "SharePoint Search Services" -Account $SPSearchPoolAccount  
 
$applicationPool = Get-SPServiceApplicationPool "SharePoint Search Services" 
 
# Gets the Search service instance and sets a variable to use in the next command 
$searchInst = Get-SPEnterpriseSearchServiceInstance -local 
 
Restore-SPEnterpriseSearchServiceApplication -Name 'SharePoint Search Service' -applicationpool $applicationPool -databasename 'Prod_Search' -databaseserver SharePointSQL -AdminSearchServiceInstance $searchInst  
 
 
$ssa = Get-SPEnterpriseSearchServiceApplication 
New-SPEnterpriseSearchServiceApplicationProxy -Name "SharePoint Search Service Proxy" -SearchApplication $ssa 
 
$ssap = Get-SPEnterpriseSearchServiceApplicationProxy 
Add-SPServiceApplicationProxyGroupMember -member $ssap -identity " "  
 
 
$newTopology = New-SPEnterpriseSearchTopology -SearchApplication $ssa 
$host1 = (Get-ChildItem env:computername).value 
$searchServiceInstance = Get-SPEnterpriseSearchServiceInstance | Where {$_.Server.Address -eq "$server"} 
New-SPEnterpriseSearchAdminComponent –SearchTopology $newTopology -SearchServiceInstance $host1 
New-SPEnterpriseSearchContentProcessingComponent –SearchTopology $newTopology -SearchServiceInstance $host1 
New-SPEnterpriseSearchAnalyticsProcessingComponent –SearchTopology $newTopology -SearchServiceInstance $host1 
New-SPEnterpriseSearchCrawlComponent –SearchTopology $newTopology -SearchServiceInstance $host1  
New-SPEnterpriseSearchIndexComponent –SearchTopology $newTopology -SearchServiceInstance $host1 
New-SPEnterpriseSearchQueryProcessingComponent –SearchTopology $newTopology -SearchServiceInstance $host1 
 
 
Set-SPEnterpriseSearchTopology -Identity $newTopology 
 
Write-Host "Search Done!" 

It will try to create a new service application named SharePoint Search Services.  So, if that application pool exists, you’ll want to delete it before running the above script, or change the name of the new service application pool.