Cleaning
up deleted databases in SharePoint
Get-SPDatabase | where {$_.exists -eq $false}
Get-SPDatabase | where {$_.exists -eq $false} | foreach {$_.delete()}
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.
Solution
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 you are happy with the result and 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.
No comments:
Post a Comment