Using PowerShell to Get Mailbox Database Size and Available New Mailbox Space
As your Exchange Server mailbox databases grow you’re eventually going to be interested in finding out two things – how large the database file is, and how much available new mailbox space is in the database.
“Available new mailbox space” is sometimes referred to as “white space”, although the folks at Microsoft will tell you that is not the correct term for it. I’ll try to stick to the correct terminology in this article.
If you’re not sure what that “available new mailbox space” means, consider this example. Let’s say you’ve got a 100Gb mailbox database, with 0Gb of available new mailbox space. If you move a 5Gb mailbox to that database you can expect the database file to grow by approximately 5Gb. If on the other hand you’ve got a 100Gb mailbox database, and recently some users have deleted content from their mailboxes, and a few mailboxes have also been deleted, there might be 10Gb of “available new mailbox space” in the database after those deleted items have been purged. The database file itself won’t shrink, but if you were to move another 5Gb mailbox to that database, it wouldn’t necessarily grow either, because it had 10Gb of “available new mailbox space” to place that data into.
That’s the simplest explanation I can provide without getting into a deep dive on ESE.
Anyway, let’s assume you’re interested to know the size and available space in your mailbox databases, and you want to use PowerShell to retrieve that information.
First, running Get-MailboxDatabase will return two properties that we’re interested in;DatabaseSize and AvailableNewMailboxSpace. I’m also retrieving the Name because I have multiple databases in this environment.
[PS] C:\>Get-MailboxDatabase | select Name,DatabaseSize,AvailableNewMailboxSpace Name DatabaseSize AvailableNewMailboxSpace ---- ------------ ------------------------ DB01 DB02 DB03 DB04 Mailbox Database 1833569659
In the output above the attributes are blank. This is because I did not use the -Status parameter for Get-MailboxDatabase, which retrieves some extra details that the default cmdlet behaviour does not.
[PS] C:\>Get-MailboxDatabase -Status | select Name,DatabaseSize,AvailableNewMailboxSpace Name DatabaseSize AvailableNewMailboxSpace ---- ------------ ------------------------ DB01 23.25 GB (24,964,497,408 bytes) 123 MB (128,942,080 bytes) DB02 25.88 GB (27,783,069,696 bytes) 184 MB (192,970,752 bytes) DB03 3 GB (3,221,225,472 bytes) 58.03 MB (60,850,176 bytes) DB04 2.625 GB (2,818,572,288 bytes) 36.63 MB (38,404,096 bytes) Mailbox Database 1833569659 768 MB (805,306,368 bytes) 179.8 MB (188,579,840 bytes)
Job done, right? Not quite. Those values are what we want to see, but they may not be useful for reporting purposes. For example, if I were to output that data to CSV file and open it in Excel, the values such as “23.25 Gb (24,964,497,408 bytes)” would not be very useful for sorting or graphing.
So instead I prefer to convert the data to a useful, consistent format, generally a rounded number of GB.
[PS] C:\>Get-MailboxDatabase -Status | sort name | select name,@{Name='DB Size (Gb)';Expression={$_.DatabaseSize.ToGb()}},@{Name='Available New Mbx Space Gb)';Expression={$_.AvailableNewMailboxSpace.ToGb()}} Name DB Size (Gb) Available New Mbx Space Gb) ---- ------------ --------------------------- DB01 23 0 DB02 25 0 DB03 3 0 DB04 2 0 Mailbox Database 1833569659 0 0
In your case MB might be more useful, depending on the size of your environment and how you plan to use the data in Excel or other applications later.
As you can see this is pretty simple information to retrieve, with the only issue being that command is a royal pain to remember and type in full each time you want to get the latest figures. So you will probably find it much easier to simply add that one-liner to a script file and run the script instead. That has the advantage of allowing you to add parameters to your script for specifying which databases to query, or to output the information to a specific format.