Monday 5 September 2016

Fix a degraded SharePoint 2013 index partition

#set Search Service Application
$ssa = Get-SPEnterpriseSearchServiceApplication

#recreate search topology with new index component
#reset the index if the bad component is the index

#grab component name of faulty topology component and it's respective server name
Get-SPEnterpriseSearchStatus -SearchApplication $ssa -Text

#put server name where [SERVER] is.. remove the []
$hosta = get-spenterprisesearchserviceinstance -identity [SERVER]

#get the existing topology
$active = Get-SPEnterpriseSearchTopology -SearchApplication $ssa -Active

#copy the existing topology
$clone = New-SPEnterpriseSearchTopology -SearchApplication $ssa -Clone -SearchTopology $active

#remove the bad component, placing the name where [BAD COMPONENT NAME] is... remove the []
$ComponentID = (Get-SPEnterpriseSearchComponent -SearchTopology $clone -Identity [BAD COMPONENT NAME]).componentID
Remove-SPEnterpriseSearchComponent -Identity $ComponentID.GUID -SearchTopology $clone -confirm:$false

#create the new component, the example below is for the index specifically - create a new folder for the index so it's empty!
New-SPEnterpriseSearchIndexComponent -SearchTopology $clone -SearchServiceInstance $hostA -IndexPartition 0 -RootDirectory F:\SPIndex

#Set this copy as the active topology
Set-SPEnterpriseSearchTopology -identity $clone