Follow by Email

Friday, June 4, 2021

Restore a search service application to another SharePoint farm

 The below script helps in restoring a search service application to another sharepoint farm. Before running below script, you need to take a back up of existing Search DB's ( with or without crawl db) to the new farms SQL server.


$saAppPoolName = "SearchService_AdminAppPool"


# Search Specifics, we are single server farm

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


#Web Front End servers


$hostA = ""Server1"

$hostB = ""Server2"



#Servers hosting Search Components


$hostD = "Server1"

$hostE = "Server2" #In case of running components on multiple servers.


$IndexLocation = "F:\Apps\SearchIndex"


$serviceAppName = "Search Service Application"

$searchDBName = "Search Admin DB"

# 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..."

$searchInstance = Get-SPEnterpriseSearchServiceInstance -local

$searchServiceApp = Restore-SPEnterpriseSearchServiceApplication -Name $serviceAppName -ApplicationPool $saAppPoolName -AdminSearchServiceInstance $searchInstance -DatabaseName $searchDBName

$searchProxy = New-SPEnterpriseSearchServiceApplicationProxy -Name "Service Application and 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..."

$clone = $searchServiceApp.ActiveTopology.Clone()


#$searchServiceInstance = Get-SPEnterpriseSearchServiceInstance


$searchServiceInstance1 = Get-SPEnterpriseSearchServiceInstance -Identity $hostD

$searchServiceInstance2 = Get-SPEnterpriseSearchServiceInstance -Identity $hostE



#We need only two admin component


New-SPEnterpriseSearchAdminComponent -SearchTopology  $clone -SearchServiceInstance $searchServiceInstance1

New-SPEnterpriseSearchAdminComponent -SearchTopology  $clone -SearchServiceInstance $searchServiceInstance2


#We need two content processing components


New-SPEnterpriseSearchContentProcessingComponent -SearchTopology  $clone -SearchServiceInstance $searchServiceInstance1

#New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $clone -SearchServiceInstance $searchServiceInstance2



#We need two analytics processing components


New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology  $clone -SearchServiceInstance $searchServiceInstance1

#New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology  $clone -SearchServiceInstance $searchServiceInstance2



#We need two crawl components


New-SPEnterpriseSearchCrawlComponent -SearchTopology  $clone -SearchServiceInstance $searchServiceInstance1

#New-SPEnterpriseSearchCrawlComponent -SearchTopology  $clone -SearchServiceInstance $searchServiceInstance2



#We need two query processing components


New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology  $clone -SearchServiceInstance $searchServiceInstance1

New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology  $clone -SearchServiceInstance $searchServiceInstance2



New-SPEnterpriseSearchIndexComponent -SearchTopology $clone -SearchServiceInstance $searchServiceInstance1 -RootDirectory $IndexLocation -IndexPartition 0

New-SPEnterpriseSearchIndexComponent -SearchTopology $clone -SearchServiceInstance $searchServiceInstance2 -RootDirectory $IndexLocation -IndexPartition 0



#New-SPEnterpriseSearchAdminComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance

#New-SPEnterpriseSearchContentProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance

#New-SPEnterpriseSearchAnalyticsProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance

#New-SPEnterpriseSearchCrawlComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance

#New-SPEnterpriseSearchIndexComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance

#New-SPEnterpriseSearchQueryProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance



$clone.Activate()


Get-SPEnterpriseSearchTopology -SearchApplication $ssa



# Additional


$ssa = Get-SPEnterpriseSearchServiceApplication "Search Service Application" 

 $admin = Get-SPEnterpriseSearchAdministrationComponent -SearchApplication $ssa

 $admin | Set-SPEnterpriseSearchAdministrationComponent -SearchServiceInstance $searchServiceInstance1 -Force 


 $si = Get-SPEnterpriseSearchServiceInstance -Identity a007f95c-e67e-4150-ab8f-7fff8a71d5b6

$varSearchApp = get-spenterprisesearchserviceapplication

Set-SPEnterpriseSearchAdministrationComponent -SearchApplication $varSearchApp -SearchServiceInstance $si



Feel free to reply in case of any queries

No comments:

Post a Comment