List all databases that are being used by SharePoint:
Get-SPDatabase | Sort-Object disksizerequired -desc | Format-Table NameUse the returned list to compare with the databases on your SQL server and delete any databases that are not on the list.
List all databases that are being used by SharePoint that are not on the database:
Get-SPDatabase | where {$_.exists -eq $false}Delete the orphaned databases:
Get-SPDatabase | where {$_.exists -eq $false} | foreach {$_.delete()}