The Script
This script was written with a specific purpose in mind, find the corrupt indexes, display which ones were corrupt and offer an option to fix the indexes (or an option to not fix them as well). The script will go through each database copy to see if they content index state is not ‘healty’. This allows the script to look for any index that is in an unstable state.
cls write-host "Checking database content indexes now." -foregroundcolor Yellow # $test =(Get-MailboxDatabase | Get-MailboxDatabasecopystatus | where {$_.contentindexstate -ne "healthy"}) if ($test -eq $null) { write-host " " write-host "No databases have failed content indexes!" -foregroundcolor cyan;write-host " " } else { write-host " " foreach ($line in $test) { $name = $line.name write-host "The database " -nonewline write-host "$name" -foregroundcolor green -nonewline write-host " has a " -nonewline write-host "failed content index" -foregroundcolor red -nonewline write-host ". Make sure to fix this." } write-host " " } write-host "Do you want to repair the failed content indexes? [y or n]" -ForegroundColor Cyan -nonewline $answer = read-host if ($answer -eq "y") { foreach ($line in $test) { $identity = $line.name # Update-MailboxDatabaseCopy -identity $identity -CatalogOnly # get-mailboxdatabase -identity $identity } }else { write-host " " write-host "Please make sure to repair your failed content indexes soon." -ForegroundColor yellow write-host " " }
Scenario One
The script can be run just as a check to verify the content indexes are in good shape. If a content index is found to be corrupt it will appear in the list as show below. Now, if you do not want to fix the indexes for change control reasons or whatever, then the script allows for an exit point to not update the indexes. The script will also remind you to fix the issues:
Scenario Two
Now if content indexes come up as failed and you can fix them automatically, the script, as show below, will allow for this to be done and report which databases it is working on:
Content Indexes – All Healthy
If the script is run either after the indexes were fixed or when they were already healthy, the script would generate this for output:
Further Reading
Issue this script will not fix
Old article on Content Indexing (27)
Exchange 2013 article on Exchange Search
Exchange Search articles on Technet
Great Script! Thanks!