none
Powershell get-mailboxstatistics sort-object question RRS feed

  • Question

  • Hello All..  When I run the following powershell it works GREAT:

    Get-Mailbox -database mydatabase | Get-MailboxStatistics | Sort-Object TotalItemSize -descending |Select-Object DisplayName,ItemCount,@{name="MailboxSize";exp={$_.totalitemsize}} -first 200 | Convertto-Html | out-File report.htm

    Most importantly to this is that it sucessfully sorts descending the largest mailboxes..

    I have this PS1:

    $session = New-PSSession -Configurationname Microsoft.Exchange –ConnectionUri http://server/powershell
    import-pssession $session

    Get-Mailbox -database mydatabase | Get-MailboxStatistics | Sort-Object TotalItemSize -descending |Select-Object DisplayName,ItemCount,@{name="MailboxSize";exp={$_.totalitemsize}} -first 200 | Convertto-Html | out-File "c:\scripts\report.htm"

    send-mailmessage -to to@myurl.com -from whatever@myurl.com -subject "Weekly mailbox size report" -smtpserver "10.10.10.12" -attachments "c:\scripts\report.htm"

    ------------------------

    When I run the script, which appears to be the same exact command, it sorts descending, but instead of the mailbox size, it sorts by number..  so it will list all of the sizes that begin with 9 first, regardles of megabytes, gigabytes or whatever.   instead of size it lists all 9s first,, 9bytes, 9 kilobytes, whatever, doesnt matter, all the 9s, then the 8s, etc.

    where as the original command when run outside of the scrip lists them by actual size.

     

    i am clueless..

     

    Monday, August 29, 2011 6:46 PM

Answers

  • Do you get the same result if your script uses the following commands (instead of New-PSSession/Import-PSSession) to connect to Exchange:

    . 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'
    Connect-ExchangeServer -auto

    Steve


    Steve Goodman
    Check out my Blog for more Exchange info or find me on Twitter

    • Marked as answer by BBQ Steak Monday, August 29, 2011 8:41 PM
    Monday, August 29, 2011 8:15 PM

All replies

  • Do you get the same result if your script uses the following commands (instead of New-PSSession/Import-PSSession) to connect to Exchange:

    . 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'
    Connect-ExchangeServer -auto

    Steve


    Steve Goodman
    Check out my Blog for more Exchange info or find me on Twitter

    • Marked as answer by BBQ Steak Monday, August 29, 2011 8:41 PM
    Monday, August 29, 2011 8:15 PM
  • LIKE A CHAMP!

     

    what the heck?

     

    thanks!

    Monday, August 29, 2011 8:41 PM
  • If you do it that way, it's launching the remote powershell session the same way as the EMS shortcut.

    I can't remember the reason why there is a difference, but I think in your example, when you sort, it's doing a .ToString() on TotalItemSize rather than evaluating the actual value.

    Steve


    Steve Goodman
    Check out my Blog for more Exchange info or find me on Twitter

    Monday, August 29, 2011 8:48 PM
  • thanks again,  i always create a session, never knew about the remoteexchange.ps1, this is great!
    Monday, August 29, 2011 10:11 PM