SharePoint 2013 : Orphaned Content Database Removal

Orphaned Content Database – By orphaned content database I mean that the content database is not associated to any web application and is not visible by using Get-SPContentDatabase command.

So, what is the need of removing the Orphaned Database. Recently, I accidentally removed a database and added it back but somehow it was not adding back and displaying the message that database already exist when I was trying to add the database using the UI or using PowerShell.

So, the way to see is the database present in the farm is to run the following command:

Get-SPDatabase | Select  Name, Id

It would display the list of all the databases associated with any service application or web application or any other database present/associated with SharePoint. In this list the orphaned content database would also be listed.

In order to remove just get the database and execute delete method. It would only remove the association with  the farm.

$db = Get-SPDatabase -Identity "<GUID>"

Now again, if you run the following command the orphaned content database would not be present anymore.

Get-SPDatabase | Select  Name, Id

I couldn’t find any blog/article anywhere related to this, hope it might help someone.