Gathering Exchange Mailbox Database Sizes
Posted by Ben Lye in Exchange, Exchange 2007, Outlook, Tutorials on 27-01-2010
Tags: databases, Exchange, Exchange 2007, Outlook
I often find that I need to list Exchange databases on a particular server by database size. Exchange 2007 doesn’t provide a mechanism to get this data directly from the management console or shell, but it’s reasonably easy to use the Exchange Management Shell to run a command which will give the answer.
The first thing to do is get a list of databases which we are interested in – it could be a list of databases on a particular server or databases which match a particular name pattern.
This is done with the Get-MailboxDatabase cmdlet:
To return all databases on a server named SERVER01:
Get-MailboxDatabase -Server SERVER01
To return databases on a server SERVER01, with “Tokyo” in the name:
Get-MailboxDatabase -Identity "SERVER01\*Tokyo*"
File sizes are returned using the Get-ChildItem cmdlet. One of the properties returned by the Get-MailboxDatabase cmdlet is EdbFilePath, which is the full path to the database’s EDB file. Get-MailboxDatabase can be combined with Get-ChildItem to list the EDB file sizes of each database (Get-ChildItem returns the file size in bytes in the Length property):
Note: This command (and the following ones as well) need to be run on the mailbox server where the databases are located, otherwise the commands would need to be modified to use UNC paths.
Get-MailboxDatabase -Server SERVER01 | ForEach {Get-ChildItem $_.EdbFilePath | Format-List Name,Length}
The output from this command will be an unsorted list of file names and sizes. If your server has many databases and you want to get the data into a more readable, sorted, format we can also do that by using a slightly more complex script to store the size information and sort it for output.
A simple way to do this is to use a hash table (sometimes also called an associative array) to store the name and size of each database, which can then be sorted smallest to largest:
# Get the databases we’re interested in
$dbs = Get-MailboxDatabase -Server SERVER01
# Declare a hash table to store the sizes
$dbsizes=@{}
# Loop through each DB getting and storing the sizes
ForEach ($db in $dbs) {$file = Get-ChildItem $db.EdbFilePath; $dbsizes.Add($db.Name,$File.Length)}
# Output the sorted results
$dbsizes.GetEnumerator() | Sort-Object Value
These commands can also be concatenated into a single line:
$dbs = Get-MailboxDatabase -Server SERVER01; $dbsizes=@{}; ForEach ($db in $dbs) {$file = Get-ChildItem $db.EdbFilePath; $dbsizes.Add($db.Name,$File.Length)}; $dbsizes.GetEnumerator() | Sort-Object Value
The output shows the database name in the left column and the EDB file size in bytes in the right column.

This is great. Thanks Ben. I am a little behind when it comes to Exchange 2007 and 2010, but am trying to learn as much as I can in the bits of spare time I do find. /me fires up the Exchange 2007 test environment to try this out.
can you say how to convert the output to MB?
@Sean – Thanks!
@Jan – the easiest way is to use built-in PowerShell conversion and divide the size by 1MB. Just replace “$dbsizes.Add($db.Name,$File.Length)” with “$dbsizes.Add($db.Name,$File.Length /1MB)”.
Ben