Powershell one-liner for gathering mailbox stats

By | January 17, 2010

 

The Get-MailboxStatistics cmdlet is great for showing a range of detailed information about the mailboxes in your organisation.  Sometimes you need to pare down the information to just the really useful stuff (such as mailbox size, item count, etc.) and push it to a CSV file.  Here’s one that I find helpful:

 

get-exchangeserver | where-object {$_.IsMailboxServer -eq $true } | `

Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | `

Select-Object DisplayName,@{label="TotalItemSize(MB)";`

expression={$_.TotalItemSize.Value.ToMB()}},`

ItemCount,ServerName,StorageGroupName,DatabaseName | `

export-csv c:\stats.csv –NoTypeInformation

8 thoughts on “Powershell one-liner for gathering mailbox stats

  1. Daniel ODonnell

    Hi,

    This looks really usefulbut I am unable to use the script as I get the following error:

    Select-Object : Illegal key label
    At line:3 char:14
    Select-Object <<<< DisplayName,@{label=”TotalItemSize(MB)”;`

    I am using powershell v1 with 2008 64 Bit Server.

    Thanks

    Daniel

    Reply
  2. Daniel ODonnell

    Hi,

    This looks really usefulbut I am unable to use the script as I get the following error:

    Select-Object : Illegal key label
    At line:3 char:14
    Select-Object <<<< DisplayName,@{label=”TotalItemSize(MB)”;`

    I am using powershell v1 with 2008 64 Bit Server.

    Thanks

    Daniel

    Reply
  3. Tony Murray

    Hi Daniel

    It might be that the formatting has changed after copy/paste from the web site. I’ve just tried it and it works for me, but in the past I have seen situations where characters like double-quotes get transformed. Try replacing the special characters in that line manually and see if it works.

    Tony

    Reply
  4. Tony Murray

    Hi Daniel

    It might be that the formatting has changed after copy/paste from the web site. I’ve just tried it and it works for me, but in the past I have seen situations where characters like double-quotes get transformed. Try replacing the special characters in that line manually and see if it works.

    Tony

    Reply
  5. www.zhengda.me

    when i changed the “lable” to “name”,it works.
    look below:
    @{name=”TotalItemSize(MB)”;`

    or not it will report “Illegal key label”

    I am also using powershell v1 with 2008 64 Bit Server.

    Thanks

    chander

    Reply
  6. www.zhengda.me

    when i changed the “lable” to “name”,it works.
    look below:
    @{name=”TotalItemSize(MB)”;`

    or not it will report “Illegal key label”

    I am also using powershell v1 with 2008 64 Bit Server.

    Thanks

    chander

    Reply

Leave a Reply

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