Removing search service application and proxy

Scenario:

You’ve determined that you don’t want to modify the search service application proxy settings under service connections under web application management and that you just want to remove the Search Service application, because there is some issue with search that calls for it’s removal.

Steps:

get-spserviceapplication | Where-Object {$_.typename -like "search service*"} | Remove-spserviceapplication -RemoveData -confirm:$false

get-spserviceapplicationproxy | Where-Object {$_.typename -like "search service*"} | Remove-spserviceapplicationproxy -RemoveData -confirm:$false

WARNING: -RemoveData is going to delete the Search Databases

WARNING:

 

If you have more than one search service application in your farm, do not use the above.

Instead use something like this

get-spserviceapplication | Where-Object {$_.displayname -like "*two"} | Remove-spserviceapplication -RemoveData -confirm:$false

get-spserviceapplicationproxy | Where-Object {$_.displayname -like "*two"} | Remove-spserviceapplicationproxy -RemoveData -confirm:$false

For example, if you had a second search service application named Search Services App Two, then this will remove it.  The earlier command that looks at typename would find all the search service application and try and remove them all.  Here’s another way to find a specific search service application using its exact display name

 

get-spserviceapplication | Where-Object {$_.displayname -eq "Enterprise Search Services"} | Remove-spserviceapplication -RemoveData -confirm:$false

get-spserviceapplicationproxy | Where-Object {$_.displayname -eq "Enterprise Search Services*"} | Remove-spserviceapplicationproxy -RemoveData -confirm:$false