Question

Here's a script I'm using to get current mailbox limits, quotas, StorageLimitStatus and TotalItemSize for Exchange 2007 mailboxes.

Get-MailboxDatabase |`
    Get-Mailbox |`
    Format-Table DisplayName,IssueWarningQuota,ProhibitSendQuota,`
        @{label="TotalItemSize";expression={(get-mailboxstatistics $_).TotalItemSize.Value.ToMB()}},`
        @{label="StorageLimitStatus";expression={(Get-MailboxStatistics $_).StorageLimitStatus}} |`
    Sort-Object -Property ********

I'd like to sort on the values contained in the two associative arrays e.g. Sort first by StorageLimitStatus, then by TotalItemSize.

My limited understanding of Powershell prevents me from building the correct Sort-Object. Any ideas?

Was it helpful?

Solution

Format-Table is going to cause you problems there. It only returns strings, so Sort-Object isn't going to find what you're looking for. Using Select-Object is a better choice (you can pipe through format-table at the end to get the table output):

Get-MailboxDatabase |`
    Get-Mailbox |`
    Select-Object DisplayName,IssueWarningQuota,ProhibitSendQuota,`
        @{label="TotalItemSize";expression={(get-mailboxstatistics $_).TotalItemSize.Value.ToMB()}},`
        @{label="StorageLimitStatus";expression={(Get-MailboxStatistics $_).StorageLimitStatus}} |`
    Sort-Object -Property StorageLimitStatus,TotalItemSize | Format-Table

As to the sorting, just list the properties you want to sort by, as in the example above.

OTHER TIPS

Per http://technet.microsoft.com/en-us/library/hh849912.aspx: If you specify multiple properties, the objects are first sorted by the first property. If more than one object has the same value for the first property, those objects are sorted by the second property.

So you could use:

| Sort-Object -Property StorageLimitStatus,TotalItemSize
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top