Wednesday, May 12, 2010

List All SharePoint 2010 Databases

If you're like me you've setup numerous SharePoint 2010 test boxes in order to get comfortable with all the great new features. Because I'm running in a test environment I hadn't been paying too much attention to the SQL server I was using. Yesterday I logged in and found a staggering number of similarly named databases which were no longer being used because the test boxes were done.

So how do you figure out which databases are which? There's a great SharePoint Powershell cmdlet you can run on your SharePoint server that will give you a list of all the databases your server is using:

Get-SPDatabase | Sort-Object disksizerequired -desc | Format-Table Name

When you run the command, you'll get a list of all the databases similar to the following:

Now that you have your list, log into SQL Server Management Studio and delete the corresponding databases:

Get-SPDatabase | Sort-Object disksizerequired -desc | Format-Table Name | out-file c:\databases.txt

You can also see how big the databases are by running the following:

Get-SPDatabase | Sort-Object disksizerequired -desc Format-Table Name, @{Label ="Size in MB"; Expression = {$_.disksizerequired/1024/1024}}


Anonymous said...

Great tip! I've been trying to figure that out for a while. Thanks

Nuredin said...

You have no idea how much headache you spared. Thank you.

Anonymous said...

You can get the same information from Central Administration > Upgrade and Migration > Review database status.