There are many posts about how to move search components from one server to another. But I cannot find a complete version to do that in one go.
It's frustrating to keep "waiting" for the current step to complete, so we can start next step. That's why I build one as below. This one assumes that the farm only has one search server which hosts all search components. And it moves all search components from the current server to a new SharePoint server.
The whole process may take more than 20 minutes.
Most of these PowerShell scripts are copied from here, thanks for the hard work of Matt Milsark.
function MoveSPSearchComponents([string]$SearchServerNameOld, [string]$SearchServerNameNew)
{
Write-Host "$(get-date -UFormat '%Y%m%d %H:%M:%S') - All 6 Search components are going to be moved from server '$SearchServerNameOld' to '$SearchServerNameNew'" -f DarkYellow
# START THE SEARCH SERVICE ON THE NEW SERVER
$ssa = Get-SPEnterpriseSearchServiceApplication
$active = Get-SPEnterpriseSearchTopology -SearchApplication $ssa –Active
$clone = New-SPEnterpriseSearchTopology -SearchApplication $ssa -Clone –SearchTopology $active
$instances = @(Get-SPEnterpriseSearchServiceInstance -Identity $SearchServerNameNew | Where-Object {$_.Status -eq "Online"})
if ($instances.Count -eq 0)
{
Start-SPEnterpriseSearchServiceInstance -Identity $SearchServerNameNew
do
{
$instances = @(Get-SPEnterpriseSearchServiceInstance -Identity $SearchServerNameNew | Where-Object {$_.Status -eq "Online"})
Write-Host "." -NoNewLine
Start-Sleep -s 1
} until ($instances.Count -gt 0)
Write-Host "Search instance on server '$SearchServerNameNew' is Online now" -f DarkGreen
}
$SearchComponents = @(Get-SPEnterpriseSearchComponent -SearchTopology $clone | Where-Object {$_.ServerName -eq $SearchServerNameNew})
$SearchComponents
$SearchComponents | Remove-SPEnterpriseSearchComponent -SearchTopology $clone -confirm:$false
Set-SPEnterpriseSearchTopology -Identity $clone
do
{
Write-Host "." -NoNewLine
Start-Sleep -s 1
$SearchComponents = @(Get-SPEnterpriseSearchComponent -SearchTopology $clone | Where-Object {$_.ServerName -eq $SearchServerNameNew})
} until ($SearchComponents.Count -eq 0)
Write-Host "$(get-date -UFormat '%Y%m%d %H:%M:%S') - Search components on server '$SearchServerNameNew' is cleaned up" -f DarkGreen
# CREATE NEW SEARCH COMPONENTS ON THE NEW SEARCH SERVER
$active = Get-SPEnterpriseSearchTopology -SearchApplication $ssa -Active
$clone = New-SPEnterpriseSearchTopology -SearchApplication $ssa -Clone –SearchTopology $active
New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $clone -SearchServiceInstance $SearchServerNameNew
New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $clone -SearchServiceInstance $SearchServerNameNew
New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $clone -SearchServiceInstance $SearchServerNameNew
New-SPEnterpriseSearchCrawlComponent -SearchTopology $clone -SearchServiceInstance $SearchServerNameNew
New-SPEnterpriseSearchIndexComponent -SearchTopology $clone -IndexPartition 0 -SearchServiceInstance $SearchServerNameNew
Set-SPEnterpriseSearchTopology -Identity $clone
do
{
Write-Host "." -NoNewLine
Start-Sleep -s 1
$SearchComponents = @(Get-SPEnterpriseSearchComponent -SearchTopology $clone | Where-Object {$_.ServerName -eq $SearchServerNameNew})
} until ($SearchComponents.Count -eq 5)
Write-Host "$(get-date -UFormat '%Y%m%d %H:%M:%S') - 5 Search components are created on server '$SearchServerNameNew' in the clone topology" -f DarkGreen
# REMOVE COMPONENTS FROM ORGINAL SEARCH SERVER
$active = Get-SPEnterpriseSearchTopology -SearchApplication $ssa -Active
$clone = New-SPEnterpriseSearchTopology -SearchApplication $ssa -Clone –SearchTopology $active
$SearchComponents = @(Get-SPEnterpriseSearchComponent -SearchTopology $clone | Where-Object {$_.ServerName -eq $SearchServerNameOld -and $_.Name -NotMatch 'AdminComponent'})
$SearchComponents | Remove-SPEnterpriseSearchComponent -SearchTopology $clone -confirm:$false
Set-SPEnterpriseSearchTopology -Identity $clone
do
{
Write-Host "." -NoNewLine
Start-Sleep -s 1
$SearchComponents = @(Get-SPEnterpriseSearchComponent -SearchTopology $clone | Where-Object {$_.ServerName -eq $SearchServerNameOld -and $_.Name -NotMatch 'AdminComponent'})
} until ($SearchComponents.Count -eq 0)
Write-Host "$(get-date -UFormat '%Y%m%d %H:%M:%S') - Search components on server '$SearchServerNameOld' are removed (except the admin component)" -f DarkGreen
# START AN ADMIN COMPONENT ON THE NEW SERVER
$active = Get-SPEnterpriseSearchTopology -SearchApplication $ssa –Active
$clone = New-SPEnterpriseSearchTopology -SearchApplication $ssa -Clone –SearchTopology $active
#$NewServer = Get-SPEnterpriseSearchServiceInstance -Identity $SearchServerNameNew
New-SPEnterpriseSearchAdminComponent -SearchTopology $clone -SearchServiceInstance $SearchServerNameNew
Set-SPEnterpriseSearchTopology -Identity $clone
do
{
Write-Host "." -NoNewLine
Start-Sleep -s 1
$SearchComponents = @(Get-SPEnterpriseSearchComponent -SearchTopology $clone | Where-Object {$_.ServerName -eq $SearchServerNameNew -and $_.Name -match 'AdminComponent'})
} until ($SearchComponents.Count -eq 1)
Write-Host "$(get-date -UFormat '%Y%m%d %H:%M:%S') - Search Admin components on server '$SearchServerNameNew' is created" -f DarkGreen
# DELETE THE OLD ADMIN COMPONENT
$active = Get-SPEnterpriseSearchTopology -SearchApplication $ssa -Active
$clone = New-SPEnterpriseSearchTopology -SearchApplication $ssa -Clone –SearchTopology $active
$SearchComponents = @(Get-SPEnterpriseSearchComponent -SearchTopology $clone | Where-Object {$_.ServerName -eq $SearchServerNameOld -and $_.Name -match 'AdminComponent'})
$SearchComponents | Remove-SPEnterpriseSearchComponent -SearchTopology $clone -confirm:$false
Set-SPEnterpriseSearchTopology -Identity $clone
do
{
Write-Host "." -NoNewLine
Start-Sleep -s 1
$SearchComponents = @(Get-SPEnterpriseSearchComponent -SearchTopology $clone | Where-Object {$_.ServerName -eq $SearchServerNameOld -and $_.Name -match 'AdminComponent'})
} until ($SearchComponents.Count -eq 0)
Write-Host "$(get-date -UFormat '%Y%m%d %H:%M:%S') - Search Admin components on server '$SearchServerNameOld' is removed" -f DarkGreen
Write-Host "$(get-date -UFormat '%Y%m%d %H:%M:%S') - All 6 Search components are moved from server '$SearchServerNameOld' to '$SearchServerNameNew'" -f DarkYellow
}
$SearchServerNameNew = $env:COMPUTERNAME
MoveSPSearchComponents "OldSearchServerName" $SearchServerNameNew
No comments:
Post a Comment