Tuesday 13 September 2016

Export All Exchange Mailbox Sizes with Powershell

Here is a script you can run on your exchange server to export a list of all mailboxes on the server and the size of each mailbox. This is useful for checking/monitoring mailbox size and usage.

First of all we need to get the name of the mailbox database to query

$mbdb = get-mailboxdatabase | select Name

Next, we use this database name in the get-mailboxstatistics cmdlet to query all mailboxes within the database and export the size from the TotalItemSize field. The list is then sorted alphabetically by display name and exported to a .csv file so it's easier to view

get-mailboxstatistics -database "$($dbname.name)" | select DisplayName, TotalItemSize | sort DisplayName | export-csv "C:\1GB-MailboxList.csv" -notype

You can also implement a "filter" of sorts so that you only export mailboxes that are bigger than a certain size. For example, you may want to know how many mailboxes you have that are larger than 1GB. To do this, we add a filter using the "where {$_.totalitemsize -ge $size}" where $size is the size value you need, in bytes.

So for the example of 1GB, the $size variable would be set to 1073741824 which is 1GB in bytes.

There is a handy utility you can use by following the link below to quickly convert the size you require from GB to bytes

http://www.convertunits.com/from/GB/to/byte

$size = "1073741824"

get-mailboxstatistics -database "$($dbname.name)" | where {$_.totalitemsize -ge $size} | select DisplayName, TotalItemSize | sort DisplayName | export-csv "C:\1GB-MailboxList.csv" -notype

No comments:

Post a Comment