Powershell get-mailboxstatistics sort-object 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..
August 29th, 2011 2:55pm

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 SteveSteve Goodman Check out my Blog for more Exchange info or find me on Twitter
Free Windows Admin Tool Kit Click here and download it now
August 29th, 2011 4:24pm

LIKE A CHAMP! what the heck? thanks!
August 29th, 2011 4:50pm

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. SteveSteve Goodman Check out my Blog for more Exchange info or find me on Twitter
Free Windows Admin Tool Kit Click here and download it now
August 29th, 2011 4:57pm

thanks again, i always create a session, never knew about the remoteexchange.ps1, this is great!
August 29th, 2011 6:20pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics