SharePoint 2010 – Cleaning up deleted databases

A service application database was deleted in SQL Server Management Studio. After a while, I noticed errors in the event viewer on the WFE and ULS logs complaining that SharePoint was not able to login to the database that I deleted. Obviously, SharePoint still thought that the database existed so I needed to find a way to remove it.

PowerShell to the rescue!  Using PowerShell, run the following command:

Get-SPDatabase | where {$_.exists -eq $false}

This will list all databases in SharePoint that no longer exist on the database server. If the list is accurate and you wish to remove the orphaned databases, run the following command:

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

All orphaned databases should now be removed and SharePoint should stop complaining about being unable to login to the non-existent database.

Leave a Reply