locked
Unexpected 2007 powershell results RRS feed

  • Question

  • Hey all,

    I'm prepping to migrate over to Exchange 2010 and am trying to get my mailboxes under control. I'm working on a powershell scriptlet that will query all of my mailbox servers and give me back the top-x results for largest mailboxes with x being whatever value I give it. Here's what I've got:

    $results = Read-Host "How many results would you like (numeric value)?"
    Get-Mailbox -resultsize $results -WarningAction SilentlyContinue | Get-MailboxStatistics -WarningAction SilentlyContinue | 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}} -auto

    It looks like it's working, however the results are varying. For example, if I specify to give me the top 5 mailboxes, the top one is 5 GB. If I specify to give me the top 50 however, the top mailbox is 5.5 GB. Similarly, the low-end is odd in that it always shows me me a handful of domain admin & system ("EXCHANGE") accounts that are nowhere near the largest. Again as an example, when I run the top 5, the latter 4 are all system/admin accounts - the last actually being 0 MB.

    It seems like my results are being abridged somehow to give me a sampling of the entire results but I don't know why. Could any of you give me some pointers on how to get this working properly?


    Wednesday, October 24, 2012 8:27 PM

Answers

  • On Wed, 24 Oct 2012 20:27:00 +0000, Ijustwantaname wrote:
     
    >I'm prepping to migrate over to Exchange 2010 and am trying to get my mailboxes under control. I'm working on a powershell scriptlet that will query all of my mailbox servers and give me back the top-x results for largest mailboxes with x being whatever value I give it. Here's what I've got: $results = Read-Host "How many results would you like (numeric value)?"
    >Get-Mailbox -resultsize $results -WarningAction SilentlyContinue | Get-MailboxStatistics -WarningAction SilentlyContinue | 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}} -auto
    >
    >
    >
    >It looks like it's working, however the results are varying. For example, if I specify to give me the top 5 mailboxes, the top one is 5 GB. If I specify to give me the top 50 however, the top mailbox is 5.5 GB. Similarly, the low-end is odd in that it always shows me me a handful of domain admin & system ("EXCHANGE") accounts that are nowhere near the largest. Again as an example, when I run the top 5, the latter 4 are all system/admin accounts - the last actually being 0 MB.
    >
    >It seems like my results are being abridged somehow to give me a sampling of the entire results but I don't know why. Could any of you give me some pointers on how to get this working properly?
     
    The "get-mailbox" is using the "-resultsize $results". Which
    "$results" are returned are arbitrary, based on a LDAP search. I'm
    pretty sure you'll want to examine ALL the mailboxes. :-)
     
    You can eliminate your "select-object" (unless the result of
    "get-mailbox" is finding some other objectclass -- which would be
    unusual) and pipe the results of "sort-object" into a "select-object":
     
    Get-Mailbox -resultsize unlimited -WarningAction SilentlyContinue |
    Get-MailboxStatistics -WarningAction SilentlyContinue | Sort-Object
    TotalItemSize –Descending | select -first $results | ft
    @{label=”User”;expression={$_.DisplayName}},@{label=”Total Size
    (MB)”;expression={$_.TotalItemSize.Value.ToMB()}},@{label=”Items”;expression={$_.ItemCount}}
    -auto
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    • Marked as answer by Ijustwantaname Thursday, October 25, 2012 1:40 PM
    Wednesday, October 24, 2012 9:58 PM

All replies

  • I suspect that part of the problem is that sort on TotalItemSize, which is a string value and will not actually sort it byte-size order. 

    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Wednesday, October 24, 2012 9:22 PM
  • On Wed, 24 Oct 2012 20:27:00 +0000, Ijustwantaname wrote:
     
    >I'm prepping to migrate over to Exchange 2010 and am trying to get my mailboxes under control. I'm working on a powershell scriptlet that will query all of my mailbox servers and give me back the top-x results for largest mailboxes with x being whatever value I give it. Here's what I've got: $results = Read-Host "How many results would you like (numeric value)?"
    >Get-Mailbox -resultsize $results -WarningAction SilentlyContinue | Get-MailboxStatistics -WarningAction SilentlyContinue | 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}} -auto
    >
    >
    >
    >It looks like it's working, however the results are varying. For example, if I specify to give me the top 5 mailboxes, the top one is 5 GB. If I specify to give me the top 50 however, the top mailbox is 5.5 GB. Similarly, the low-end is odd in that it always shows me me a handful of domain admin & system ("EXCHANGE") accounts that are nowhere near the largest. Again as an example, when I run the top 5, the latter 4 are all system/admin accounts - the last actually being 0 MB.
    >
    >It seems like my results are being abridged somehow to give me a sampling of the entire results but I don't know why. Could any of you give me some pointers on how to get this working properly?
     
    The "get-mailbox" is using the "-resultsize $results". Which
    "$results" are returned are arbitrary, based on a LDAP search. I'm
    pretty sure you'll want to examine ALL the mailboxes. :-)
     
    You can eliminate your "select-object" (unless the result of
    "get-mailbox" is finding some other objectclass -- which would be
    unusual) and pipe the results of "sort-object" into a "select-object":
     
    Get-Mailbox -resultsize unlimited -WarningAction SilentlyContinue |
    Get-MailboxStatistics -WarningAction SilentlyContinue | Sort-Object
    TotalItemSize –Descending | select -first $results | ft
    @{label=”User”;expression={$_.DisplayName}},@{label=”Total Size
    (MB)”;expression={$_.TotalItemSize.Value.ToMB()}},@{label=”Items”;expression={$_.ItemCount}}
    -auto
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    • Marked as answer by Ijustwantaname Thursday, October 25, 2012 1:40 PM
    Wednesday, October 24, 2012 9:58 PM
  • That was it precisely, Rich. Thank you very much!
    Thursday, October 25, 2012 1:40 PM