In my last blog , Part 1  I discussed the scenario where we had provisioned a Search Service application using PowerShell and how it causes issues while renaming the Search Property and Crawl databases. In this blog, I am including a script to fix the existing Search Service Applications.

If we have existing Search Service Applications that were created using the problem PowerShell Script, we will not be able to rename the Crawl and Property databases for these SSAs in the UI. So what if you need to rename them?

Well, solution is simple. We can write the PowerShell script to fix it. I am including a sample script to fix the existing Search Service Applications so that it will allow us to rename the Crawl and Property databases. This scripts loops and lists out all the Inactive search topologies. It then offers whether to delete them. If we choose “Yes”, it will delete all the Inactive search topologies.

Disclaimer:

Sample Code is provided for the purpose of illustration only and is not intended to be used in a production environment. THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. We grant you a nonexclusive, royalty-free right to use and modify the Sample Code and to reproduce and distribute the object code form of the Sample Code, provided that. You agree: (i) to not use Our name, logo, or trademarks to market Your software product in which the Sample Code is embedded; (ii) to include a valid copyright notice on Your software product in which the Sample Code is embedded; and (iii) to indemnify, hold harmless, and defend Us and Our suppliers from and against any claims or lawsuits, including attorneys’ fees, that arise or result from the use or distribution of the Sample Code.

##### *********************************************

# This is a sample script. It is provided as is. Please modify it and fine tune it as per your environment and business needs.

# In no way this is to be considered as a production ready script.

# Environment specific settings

$SSAName = "<Name of existing SSA>"

## Initially we will list the inactive Crawl and Query topologies

$bFlag = 0;

Write-Host "`nQuery Topologies which are inactive:" -foregroundcolor green -backgroundcolor black

$QueryTopologies = Get-SPEnterpriseSearchQueryTopology -SearchApplication $SSAName

foreach($QueryTopology in $QueryTopologies)

{

if($QueryTopology.State -eq "Inactive")

{

Write-Host " Id: " $QueryTopology.Id ", Status: " $QueryTopology.State -foregroundcolor green -backgroundcolor black

Write-Host "`n"

$bFlag = 1;

}

}

Write-Host "Crawl Topologies which are inactive:" -foregroundcolor green -backgroundcolor black

$CrawlTopologies = Get-SPEnterpriseSearchCrawlTopology -SearchApplication $SSAName

foreach($CrawlTopology in $CrawlTopologies)

{

if($CrawlTopology.State -eq "inactive")

{

Write-Host " Id: " $CrawlTopology.Id ", Status: " $CrawlTopology.State -foregroundcolor green -backgroundcolor black

Write-Host "`n"

$bFlag = 1;

}

}

## Delete after getting confirmation.

if($bFlag -ne 1)

{

return;

}

$Delete = read-host -prompt "Do you want to delete all the crawl/Query Topologies which are inactive?`n (Y/N)"

if($Delete -eq "Y")

{

Write-Host "Deleting the Query Topologies which are inactive....." -foregroundcolor green -backgroundcolor black

foreach($QueryTopology in $QueryTopologies)

{

if($QueryTopology.State -eq "Inactive")

{

Write-Host " Deleting Query Topology --- Id: " $QueryTopology.Id -foregroundcolor green -backgroundcolor black

Write-Host "`n"

$QueryTopology.Delete();

}

}

Write-Host "Deleting the Crawl Topologies which are inactive....." -foregroundcolor green -backgroundcolor black

foreach($CrawlTopology in $CrawlTopologies)

{

if($CrawlTopology.State -eq "inactive")

{

Write-Host " Deleting Crawl Topology --- Id: " $CrawlTopology.Id -foregroundcolor green -backgroundcolor black

Write-Host "`n"

$CrawlTopology.Delete();

}

}

## We are done here.

Write-Host "Done." -foregroundcolor green -backgroundcolor black

return

}

if($Delete -eq "N")

{

Write-Host "You chose N" -foregroundcolor green -backgroundcolor black

return

}

Write-Host "You chose wrong option" -foregroundcolor green -backgroundcolor black

##### *********************************************

 

Author: Pradeep Martin Anchan [MSFT]