locked
Powershell command to filter users by email address and display mailbox size RRS feed

  • Question

  • Hi all,

    Looking for some advice on using a powershell script to generate a list of users in our Exchange 2010. I'd like to filter out by primary smtp address and from that generate the corresponding users mailbox size. This is what I have so far

    get-mailbox | ? {$_.PrimarySMTPAddress -like "*domain.com"} Select DisplayName,Alias,PrimarySMTPAddress,TotalMailboxSize

    With this the list of users generated provides the TotalMailboxSize column to be blank.

    Any feedback is highly appreciated.

    Thanks.

    BL


    bl

    Friday, January 20, 2017 3:37 PM

Answers

  • Berlan, I've used these commands since before Exchange 2010 SP1 and they have always worked for me (to the best of my knowledge).  However, let's see if the following will give you what you need:

    get-mailbox | ? {$_.PrimarySMTPAddress -like "*domain.com"} | Sort Name | % { $MbxDirData = $_ ; Get-MailboxStatistics $_ } | Select DisplayName, @{E={ $MbxDirData.Alias };L='Alias'}, @{E={ $MbxDirData.PrimarySMTPAddress };L='PrimarySMTPAddress'}, @{E={ $_.TotalItemSize.Value + $_.TotalDeletedItemSize.Value };L="TotalMailboxSize"}

    Let me know what you get from this ...


    Will Martin ...
    -join ('77696c6c406d617274696e2d66616d696c6965732e6f7267' -split '(?<=\G.{2})' | ? { $_ } | % { [char][int]"0x$_" })

    • Marked as answer by berlan Thursday, January 26, 2017 4:48 PM
    Thursday, January 26, 2017 12:35 PM

All replies

  • Get-Mailbox doesn't return mailbox size.  You want to run the following:

    get-mailbox | ? {$_.PrimarySMTPAddress -like "*domain.com"} | Select DisplayName,Alias,PrimarySMTPAddress,@{E={ $MbxData = Get-MailboxStatistics $_ ; $MbxData.TotalItemSize + $MbxData.TotalDeletedItemSize };L="TotalMailboxSize"}

    This takes the mailbox info you have and adds the mailbox statistics TotalItemSize and TotalDeletedItemSize together to get the TotalMailboxSize.


    Will Martin ...
    -join ('77696c6c406d617274696e2d66616d696c6965732e6f7267' -split '(?<=\G.{2})' | ? { $_ } | % { [char][int]"0x$_" })

    Friday, January 20, 2017 4:41 PM
  • Hi,

    Thanks for your input. I tried the command you suggested however I still get the same result. The TotalMailboxSize column is still blank.


    bl

    Monday, January 23, 2017 4:26 PM
  • I just ran it (verbatim - copied from here, removed the domain.com filter, then pasted into my test system) and it ran fine.  However, you can also try the following:

    get-mailbox | ? {$_.PrimarySMTPAddress -like "*domain.com"} | Select DisplayName,Alias,PrimarySMTPAddress,@{E={ $MbxData = Get-MailboxStatistics $_ ; $MbxData.TotalItemSize.Value + $MbxData.TotalDeletedItemSize.Value };L="TotalMailboxSize"}

    That command also worked in my system, and gave the same results, visibly. The difference between these two is that the former works with items of type Microsoft.Exchange.Data.Unlimited`1, which has a Value and an IsUnlimited property. The latter takes the value of the Microsoft.Exchange.Data.Unlimited`1 type and ends up with a Microsoft.Exchange.Data.ByteQuantifiedSize, which is always positive and can't be "unlimited".


    Will Martin ...
    -join ('77696c6c406d617274696e2d66616d696c6965732e6f7267' -split '(?<=\G.{2})' | ? { $_ } | % { [char][int]"0x$_" })

    Monday, January 23, 2017 4:47 PM
  • Very strange that my results have not changed.

    Perhaps its a limitation of my Exchange 2010? Its sp2, no rollups.


    bl

    Monday, January 23, 2017 4:58 PM
  • Hi bl,

    Thanks for your reply.

    Per my test, please run below command:

    Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Select DisplayName, ItemCount, TotalItemSize, TotalDeletedItemSize | Sort-Object TotalItemSize, TotalDeletedItemSize -Descending | Export-CSV C:\temp\MBSizes.csv

    Test results:

    Hope it’s helpful for you.


    Regards,

    Jason Chao


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Tuesday, January 24, 2017 8:49 AM
    Moderator
  • Update - I tried Jason's recommendation but it does not include the primary smtp address. When I add PrimarySMTPAddress to the command the result displayed for that field is still blank.

    bl

    Wednesday, January 25, 2017 2:42 PM
  • Berlan, I've used these commands since before Exchange 2010 SP1 and they have always worked for me (to the best of my knowledge).  However, let's see if the following will give you what you need:

    get-mailbox | ? {$_.PrimarySMTPAddress -like "*domain.com"} | Sort Name | % { $MbxDirData = $_ ; Get-MailboxStatistics $_ } | Select DisplayName, @{E={ $MbxDirData.Alias };L='Alias'}, @{E={ $MbxDirData.PrimarySMTPAddress };L='PrimarySMTPAddress'}, @{E={ $_.TotalItemSize.Value + $_.TotalDeletedItemSize.Value };L="TotalMailboxSize"}

    Let me know what you get from this ...


    Will Martin ...
    -join ('77696c6c406d617274696e2d66616d696c6965732e6f7267' -split '(?<=\G.{2})' | ? { $_ } | % { [char][int]"0x$_" })

    • Marked as answer by berlan Thursday, January 26, 2017 4:48 PM
    Thursday, January 26, 2017 12:35 PM
  • Will,

    It worked exactly as I needed! Now I can take that and export it out to a CSV. Thank you very much for your assistance with this. Much appreciated.

    BL


    bl

    Thursday, January 26, 2017 5:13 PM