Get Mailbox Database Size and Convert Default Item Size Values

I am looking at extracting mailbox database sizes for a number of users which match a certain filter for the primary SMTP address in Microsoft Exchange 2010 and export this to a CSV file.

Firstly, I need to return all mailboxes for users matching my filter, in this example it is when the primary SMTP address can be like two domains.

Get-Mailbox | Where-Object {$_.PrimarySMTPAddress -like "*" -or $_.PrimarySMTPAddress -like ""}

Now, that I have all the mailboxes that match my filter I will pipe the output to the Get-MailboxStatistics cmdlet to return the Display Name and Total Item Size.

Get-MailboxStatistics | Select DisplayName, TotalItemSize

This will return the information I require, but the Total Item Size will be displayed in both MB and bytes.

DisplayName TotalItemSize
----------- -------------
User1       1.992 MB (2,088,411 bytes)

I am required to return the Total Item Size output in MB only, therefore I will be required to create an expression for the Total Item Size and convert the original value into MB.

@{expression={$_.TotalItemSize.Value.ToMB()}; label="TotalItemSizeMB"}

So lets put the full script together and export this to a CSV file.

Get-Mailbox | Where-Object {$_.PrimarySMTPAddress -like "*" -or $_.PrimarySMTPAddress -like "*"} | Get-MailboxDatabaseStatistics | Select DisplayName, @{expression={$_.TotalItemSize.ValueToMB(); label="TotalItemSizeMB"}

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s