Hello,
I’m trying to optimize a poller for our environment and ran into a weird thing–I don’t know what to make of it. I tested various code on the exchange server and it was running faster than the original code. Then I tried it again in a PSSession to see if it is still faster remotely, but in the session it broke. Turns out, get-mailboxstatistics | sort-object works differently in a PSSession than the exchange console. I’ll demonstrate with an example.
On the server, I run
C:\Windows\system32>get-mailboxstatistics -server server.domain.com | sort-object -property totalitemsize -descending | select-object -first 1 property totalitemsize
TotalItemSize
7.782 GB (8,355,492,557 bytes)
Then on my workstation I create a PSSession and run the same command
$cred = get-credential
$session = new-possession -connectionuri https://server.domain.com/powershell -configurationname Microsoft.exchange -credential $cred -authentication negotiate -allowredirection
import-possession $session
get-mailboxstatistics -server server.domain.com | sort-object -property totalitemsize -descending | select-object -first 1 -property totalitemsize
TotalItemSize
993.9 MB (1,042,175,940 bytes)
By playing with permutation, I found that sort-object in the PSSession sorts from the left, so 7.782 GB is smaller than 993.9 MB. Sort-object running directly on the server sorts the value of byes, the number in the parenthesis. But why? Is this a bug, a problem in our environment, known behavior, or a feature?