Balaji
unread,Nov 12, 2008, 3:13:15 PM11/12/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Exchange User Group
Dear All,
One of the comments I hear often by Exchange admins who move from a
legacy version of Exchange to Exchange 2007, is that they can’t find
how to see a list of users and their mailbox sizes.
In earlier versions of Exchange, we could look in the Exchange console
and see mailbox sizes on a per database basis. Not bad, but better
than what we have in the Exchange 2007 GUI.
Fortunately, we can use PowerShell to see the information we need.
And, we have more control over how the information is displayed, as
well as what information is displayed. Let’s fire up PowerShell and
get started.
We can use the Get-MailboxStatistics cmdlet and supply a username like
this:
Get-MailboxStatistics [username]
This shows the DisplayName, ItemCount, StorageLimitStatus, and
LastLogonTime fields for the specified user.
But that doesn’t show what we need. We can have the cmdlet display
just specific fields, such as DisplayName, ItemCount, and
TotalItemSize, which will show the size of the mailbox. For that, we
use the FT command, short for Format-Table, along with the fields we
want.
Get-MailboxStatistics [username] | ft DisplayName, TotalItemSize,
ItemCount
This shows us the size of the mailbox in bytes, as well as the number
of items, and the username.
We can add another field to show if the user is above or below the
storage limits by including the StorageLimitStatus,
Get-MailboxStatistics [username] | ft DisplayName, TotalItemSize,
ItemCount, StorageLimitStatus
Showing data for all users
---------------------------------------
Now that we can see the specific fields, we can remove the [username]
parameter and the command will show us the information all users,
Get-MailboxStatistics ft DisplayName, TotalItemSize, ItemCount,
StorageLimitStatus
Filtering results
------------------------
As you can see, this will show us system mailbox sizes as well, which
probably doesn’t do us any good. So let’s filter them out. We add
right after Get-MailboxStatistics to help.
| where {$_.ObjectClass –eq “Mailbox”)
Note – that’s a pipe at the beginning. This code essentially says to
only display those objects classified as mailboxes. From the above
cmdlet we get a cleaner list.
Sorting results
---------------------
So that shows us all of the users and their sizes, but they appear in
a random, unsorted order, which doesn’t do anyone any good. In
PowerShell, we can sort using the Sort-Object cmdlet. Right after our
filter we add,
| Sort-Object TotalItemSize –Descending
This tells PowerShell to sort according to the TotalItemSize parameter
(the size of the mailbox) of the Get-MailboxStatistics results, in
descending order.
Customizing results
-------------------------------
This is all fine and good, but having to figure out how big a mailbox
is based on the number of bytes is more math than we should have to
use. Fortunately, we can convert bytes to MB by replacing the
“TotalItemSize” field with as shown below,
@{expression={$_.TotalItemSize.Value.ToMB()}
This converts the values of TotalItemSize to megabytes. If you’ve got
monster mailboxes, you could use replace ToMB with ToGB to convert to
Gigabytes. Now the value is much easier to understand. But doing this
causes the column header to be mangled. Not so good. Fortunately, we
can customize this by amending the code.
@{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}
Which gives us a much friendlier header. Based on those results, we
might as well clean up the rest of the headers, so we customize the
ItemCount using,
@{label=”Items”;expression={$_.ItemCount}}
StorageLimitStatus using,
@{label=”Storage Limit”;expression={$_.StorageLimitStatus}}
And finally, the DisplayName using
@{label=”User”;expression={$_.DisplayName}}
The text between the quotes is what the column header will say. What
we end up with is a much more readable report on the mailbox sizes of
our users.
Bringing in all together
---------------------------------
We can bring the columns closer together by using the –auto switch
which gives us our desired results as shown below,
Get-MailboxStatistics | where {$_.ObjectClass –eq “Mailbox”} | Sort-
Object TotalItemSize –Descending | ft @{label=”User”;expression=
{$_.DisplayName}},@{label=”Total Size (MB)”;expression=
{$_.TotalItemSize.Value.ToMB()}},@{label=”Items”;expression=
{$_.ItemCount}},@{label=”Storage Limit”;expression=
{$_.StorageLimitStatus}} -auto
We don't have to type all the above code in the command prompt but we
can save it in a file and execute.
We can copy and paste that code into Notepad, and save it as Get-
MailboxSizes.ps1 in the scripts folder. Then, we need to simply open
PowerShell, type
Get-MailboxSizes and we get our result.
With PowerShell, we were able to take a simple cmdlet, filter and sort
the results, give the results more human names, and convert values
into amounts that make sense. We could further filter the data so that
only users on a specific server, or a specific mailbox database are
displayed, and even export to a .csv file. The possibilities are
endless.