Recovering from a corrupted SharePoint 2010 Installation that would not create a Search Service Application

After a perfect storm of urgent and ill implemented security measures during a series of updates to SharePoint Server 2010 we were left with a corrupted production SharePoint 2010 installation. The symptoms were that some Web Application databases reported that some components were still updating and we could not create a search service application. These are the steps we went through to repair the installation.

Login as service account used for sptimerv4.
Make sure service account is dbo for all sp dbs plus the master.
Make sure service account is in administrators group, and all iis created groups.
Rerun sharepoint products configuration wizard from start.

psconfig.exe -cmd upgrade -inplace b2b -wait -force

Delete everything in C:\ProgramData\Microsoft\SharePoint\Config\ EXCEPT the cache.ini
Edit cache.ini change number to 1

Stop sptimerv4

stsadm -o setproperty -pn command-line-upgrade-running -pv No

Start sptimerv4

psconfig.exe -cmd upgrade -inplace b2b -wait -force

Rerun sharepoint products configuration wizard as admin from start.
Check version of C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\*.dll

psconfig -cmd installfeatures
psconfig -cmd secureresources
psconfig -cmd services -install
psconfig -cmd upgrade -inplace b2b -wait -force
iisreset /noforce
Upgrade-SPContentDatabase wss_content_sitecollectiondb
Upgrade-SPContentDatabase wss_content_othersitecollectiondb

Deleted unupgradeable datatases:
wss_content_sitecollectiondb
wss_content_othersitecollectiondb

Tell SharePoint that the databases are gone

Get-SPDatabase | where {$_.exists -eq $false}
Get-SPDatabase | where {$_.exists -eq $false} | foreach {$_.delete()}

Rerun sharepoint products configuration wizard as admin from start.

Go to add or remove programs, right click on sharepoint 2010 server and select repair.

Run the SharePoint 2010 configuration wizard, this time remove SharePoint server from farm then add sharepoint server back to the farm.

Run the SharePoint 2010 configuration wizard, this time remove SharePoint server from farm then create new SharePoint farm.

After we created a new SharePoint farm, all of the errors went away and were are again able to create search service applications. It appears to me that the corruption happened in the SharePoint_Config and the Web Application / Root Site Collection database.

In CA, Recover Data from an Unattached Content Database, chose the wss_content_sitecollectiondb, and exported site.

import-spweb -identity https://SharePointServer -path c:\temp\recoverexport.cmp