List of mailboxes on server sorted by mailbox size

Posted on 2012-08-14
1 Ratings
Last Modified: 2012-08-25
I have an Exchange 2007 server named It has about 2000 mailboxes.

I need a list of mailboxes on this server, sorted by size (MB), that includes:

Email Address

I should also be able to export this to CSV.

Any ideas how to do this in Powershell?
Question by:richlionel
    LVL 13

    Expert Comment

    Can you try:

    Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}}, Alias, PrimarySmtpAddress
    LVL 52

    Expert Comment

    Get-Mailbox | Get-MailboxStatistics | Sort totalitemsize -desc | ft displayname, totalitemsize, itemcount

    get-mailbox | get-mailboxstatistics | select-object displayname, itemcount,  lastloggedonuser, lastlogontime, lastlogofftime, servername, databasename, @{ expression={$_.TotalItemSize.Value.ToKB()} }

    - Rancy
    LVL 13

    Expert Comment

    Full command to csv:

    Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}}, Alias, PrimarySmtpAddress|export-csv C:\stats.csv
    LVL 9

    Accepted Solution

    I'm going to take a different tactic here, some of the fields you want are in the Get-Mailbox command, some are in the Get-MailboxStatistics command, so you really want to combine them.

    My script gets the mailboxes, then loops through each and adds in the Mailbox Size value in Mb. Then it sorts by this field descending, and selects the values you asked for.

    I think this does what you want quite elegantly and in an easy-to-understand fashion. Set the -ResultSize parameter to "Unlimited" once you've tested it.

    $Mailboxes = Get-Mailbox -ResultSize 20
    foreach ($Mailbox in $Mailboxes)
    	$Mailbox | Add-Member -MemberType "NoteProperty" -Name "MailboxSizeMB" -Value ((Get-MailboxStatistics $Mailbox).TotalItemSize.Value.ToMb())
    $Mailboxes | Sort-Object MailboxSizeMB -Desc | Select DisplayName, Alias, PrimarySMTPAddress, MailboxSizeMB

    Open in new window

    To export the data just change the last line to:

    $Mailboxes | Sort-Object MailboxSizeMB -Desc | Select DisplayName, Alias, PrimarySMTPAddress, MailboxSizeMB | Export-Csv -NoType "C:\Mailboxes.csv"

    Open in new window

    LVL 9

    Expert Comment

    @richlionel - One of my problems with Experts Exchange is when you put time and effort into helping someone who is asking a question and they don't even acknowledge it or anything. Please don't do this.

    3 of us have tried to help you, please either mark one or more of the answers as the right ones sharing the points out, or instead let us know if you need more help.
    LVL 52

    Expert Comment

    chrismerritt: I agree totally with you :)
    richlionel: As said it very Important you share your feedback so that if something isnt working we can try to tweek and assist you :)

    - Rancy

    Author Comment

    I apologise, I was ill for a few days.

    I really appreciate the help from everyone in answering! I marked ChrisMerrit's answer as the correct one since that is the one I used and it did exactly what I wanted quite well.  I hope that is the right way to do things (I'm quite new to EE).

    But, everyone, thanks again! I appreciate EVERYONE's input.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Use email signature images to promote corporate certifications and industry awards.
    ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
    In this video we show how to create a User Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Mailb…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now