Quick Tip: How To Check Exchange Database Size with PowerShell

by Mike Pfeiffer on May 24, 2010

Checking your Exchange database size in PowerShell is key in several scripting scenarios, such as creating mailboxes in the smallest database, or generating basic database reports. The problem in Exchange 2007 was that this was a lot harder than it sounded. The Get-MailboxDatabase cmdlet did not return the size of the database. If you needed to determine the database size, you had to write some fairly lengthy code to get what you think would be be easily accessible information.

Exchange 2007

There are a couple methods you can use to get this information in Exchange 2007. Here is a great example posted by Gary Siepser; it's a one-liner that retrieves the database size using WMI, allowing you to run it against clustered mailbox servers:

Get-MailboxDatabase | foreach-object {add-member -inputobject $_ -membertype noteproperty -name mailboxdbsizeinGB -value ([math]::Round(([int64](get-wmiobject cim_datafile -computername $_.server -filter ('name=''' + $_.edbfilepath.pathname.replace("\","\\") + '''')).filesize / 1GB),2)) -passthru} | Sort-Object mailboxdbsizeinGB -Descending | format-table identity,mailboxdbsizeinGB

Exchange 2010

Fortunately, the Get-MailboxDatabase cmdlet in Exchange 2010 provides this information for us out of the box. All you need to do is use the Status parameter and you can access the information using the DatabaseSize property. Here is an example:

Get-MailboxDatabase -Status | select ServerName,Name,DatabaseSize

I actually used this technique in another post, but didn't explain it in depth. I recently noticed someone still doing it "the hard way" and I realized this may make for a good quick tip – hope it helps.

Related Posts

{ 2 trackbacks }

Tweets that mention Quick Tip: How To Check Exchange Database Size with PowerShell -- Topsy.com
May 24, 2010 at 10:51 pm
Script: Check Exchange 2007 Database size with PowerShell – Bryan's Tech KB
October 10, 2010 at 11:51 am

{ 4 comments… read them below or add one }

Owais Pathan March 21, 2011 at 1:44 am

Hi Mike,

Thanks its useful for me, but is there any way to get the usage report of each database with powershell ?

or any other easy way to get the usage report of databases…

Thanks

Reply

Mike Pfeiffer March 21, 2011 at 7:24 am

Sure, what other details are you looking for? Have you seen this? http://www.mikepfeiffer.net/2010/03/exchange-2010-database-statistics-with-powershell/

Reply

pierre July 7, 2011 at 1:49 am

Thank you, very helpfull !

Reply

Eric September 29, 2011 at 5:34 pm

Perfect. Thanks!

Reply

Leave a Comment

Previous post:

Next post: