Obtaining Databases sizes in Exchange 2007

I’m taking a trip back in time for a client at the moment. In Exchange 2010 I’m used to running:

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

To get an overview of the size of my databases.

However, in the days of yore with Exchange 2007 there is no DatabaseSize property. There are several articles which point to a variant of

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

Which uses the Computername and database path to return the flat file size of the database on the disk.

I have a problem with this script in my current environment where the identity and name of the databases are not the same, so the above script fails. I get around this by assigning the databases to a variable and then iterating through each database, like so:

$Databases = Get-MailboxDatabase
FOREACH ($Database in $Databases) {
    Get-MailboxDatabase -identity $Database.identity | FOREACH {
        Add-Member -inputobject $_ -membertype noteproperty -name DatabaseSizeInGB -value ([math]::Round(([int64](get-wmiobject cim_datafile -computername $_.server -filter ('name=''' + $_.edbfilepath.pathname.replace("\","\\") + '''')).filesize / 1GB),2)) -passthru
        } | Sort-Object Name | Format-Table Name,DatabaseSizeInGB

This is great and returns the required information, but the output is pretty shonky and not great for quick manual parsing:


I have created a script that relies on an array in order to display the information in a much simpler format:

$a = @{Expression={$_.Name};Label="Database Name";width=27}, `
@{Expression={([math]::Round(([int64](Get-WMIObject cim_datafile -computername $_.server -filter ('name=''' + $_.edbfilepath.pathname.replace("\","\\") + '''')).filesize / 1GB),2))};Label="Size in GB";width=12}
Get-MailboxDatabase | Format-Table $a

With a much improved output:


Posted in Guides Tagged with: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *