Sorting properties from get-mailbox on a single mailbox, how?

get-aduser username -Properties *  gives a nicely sorted list of the properties for a user's AD account. 

get-mailbox username | fl * gives a nicely unsorted list of the properties for a user's Exchange mailbox.

Anything more elegant for sorting the get-mailbox output?

Get-Mailbox username | fl * | Out-File -FilePath c:\username-mailbox.txt
Get-Content C:\username-mailbox.txt | sort

What is the technical terminology for the type of output produced by get-mailbox username?

Thank you for your time, Joe

July 9th, 2012 5:36pm

Sort before formatting or outputting.

Bill

  • Proposed as answer by Bigteddy Monday, July 09, 2012 5:42 PM
  • Unproposed as answer by Bigteddy Monday, July 09, 2012 7:41 PM
Free Windows Admin Tool Kit Click here and download it now
July 9th, 2012 5:40pm

What is the technical terminology for the type of output produced by get-mailbox username?

Thank you for your tim

July 9th, 2012 5:44pm

Bill, I've tried all sorts of sorting...  There isn't any returned properties to sort on (i.e. | sort Name)

This might help, thanks Grant.

[PS] C:\>(get-mailbox username).gettype()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Mailbox                                  Microsoft.Exchange.Data.Directory.Management.MailEnabledOrgPerson


[PS] C:\>(get-mailbox username | fl *).gettype()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]                                 System.Array

Here's example output (similar to a get-aduser, just not sorted):

RoleAssignmentPolicy                   : Default Role Assignment Policy
SharingPolicy                          : Default Sharing Policy
RemoteAccountPolicy                    :
MailboxPlan                            :
ArchiveDatabase                        : EX-DAG01-DB08
ArchiveGuid                            : 587bdddd-f651-4e11-87d0-88ae31dc24db
ArchiveQuota                           : 50 GB (53,687,091,200 bytes)
ArchiveWarningQuota                    : 45 GB (48,318,382,080 bytes)
ArchiveDomain                          :
ArchiveStatus                          : None
RemoteRecipientType                    : None
DisabledArchiveDatabase                :
DisabledArchiveGuid                    : 00000000-0000-0000-0000-000000000000
QueryBaseDNRestrictionEnabled          : False
MailboxMoveTargetMDB                   :
MailboxMoveSourceMDB                   :
MailboxMoveFlags                       : None
MailboxMoveRemoteHostName              :
MailboxMoveBatchName                   :
MailboxMoveStatus                      : None
IsPersonToPersonTextMessagingEnabled   : False
IsMachineToPersonTextMessagingEnabled  : True
UserSMimeCertificate                   : {}

 Tha
Free Windows Admin Tool Kit Click here and download it now
July 9th, 2012 6:10pm

Hi,

(get-mailbox username | fl *).gettype() isn't going to tell you what you need to know, because fl (format-list) outputs an array of PSObject objects. This is why you need to sort first.

Bill

July 9th, 2012 6:23pm

Hear ya Bill.  But I'm only returning a single PSObject (Microsoft.Exchange.Data.Directory.Management.MailEnabledOrgPerson), and I'm attempting to sort the properties on the single object.  Sorry I'm not explaining this well.

Example Output from: get-mailbox

 

Name                   Alias                ServerName       ProhibitSendQuota
----                      -----                ----------       -----------------
kcarael               kcarael               svrwmail     unlimited
cuqt3                  cuqt3                  svrwmail     unlimited
lsren                  lsren                  exchange03   unlimited
roreerb                roreerb                      exchange03   unlimited
pacffsdfs              pacffsdfs                       exchange03   unlimited
beon                  beon                  exchange03   unlimited

 

Not a problem to sort:  get-mailbox | sort alias

 

Output from: get-mailbox someuser

 

Name                   Alias                ServerName       ProhibitSendQuota
----                      -----                ----------       -----------------
someuser              someuser              mbxn04    12.6 GB (13,529,147,392 bytes) 

 

Example Output from: get-mailbox someuser | fl * (or get-mailbox someuser | Select-Object *)

 

RoleAssignmentPolicy                   : Default Role Assignment Policy
SharingPolicy                          : Default Sharing Policy
RemoteAccountPolicy                    :
MailboxPlan                            :
ArchiveDatabase                        : EX-DAG01-DB08
ArchiveGuid                            : 587bdddd-f651-4e11-87d0-88ae31dc24db
ArchiveQuota                           : 50 GB (53,687,091,200 bytes)
ArchiveWarningQuota                    : 45 GB (48,318,382,080 bytes)
ArchiveDomain                          :
ArchiveStatus                          : None
RemoteRecipientType                    : None
DisabledArchiveDatabase                :
DisabledArchiveGuid                    : 00000000-0000-0000-0000-000000000000
QueryBaseDNRestrictionEnabled          : False
MailboxMoveTargetMDB                   :
MailboxMoveSourceMDB                   :
MailboxMoveFlags                       : None
MailboxMoveRemoteHostName              :
MailboxMoveBatchName                   :
MailboxMoveStatus                      : None
IsPersonToPersonTextMessagingEnabled   : False
IsMachineToPersonTextMessagingEnabled  : True
UserSMimeCertificate                   : {}

 

I'm not sure what to sort on...  I've tried just: get-mailbox someuser | Select-Object * | sort

 

The output looks the same as output from: get-aduser someuser 

 

This doesn't work either: get-aduser someuser | sort -descending

 

Thank you, Joe 

Free Windows Admin Tool Kit Click here and download it now
July 9th, 2012 7:32pm

It can't be done.  Get-Mailbox returns a single object in this case, and you can't sort the output.  Believe me, I've tried.  Writing to a text file forces the output into lines, which can then be sorted.  This is the only way I can see of doing this, clumsy as it
July 9th, 2012 7:42pm

Hi,

I don't have the Exchange cmdlets, but I believe you are looking for something like

Free Windows Admin Tool Kit Click here and download it now
July 9th, 2012 7:46pm

Nice try, but no cigar!

PS C:\Scripts> (Get-Mailbox grant).getenumerator()
Method invocation failed because [Microsoft.Exchange.Data.Directory.Management.Mailbox] doesn't contain a method named 'getenumerator'.
At line:1 char:34
+ (Get-Mailbox grant).getenumerator <<<< ()
    + CategoryInfo          : InvalidOperation: (getenumerator:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 

July 9th, 2012 7:52pm

Sorry; I don't have the Exchange cmdlets.

Bill

Free Windows Admin Tool Kit Click here and download it now
July 9th, 2012 8:05pm

Try this:

$mailbox=Get-MailBox testuser
$mailbox.psbase.PropertyNames | sort

July 9th, 2012 8:57pm

Perhaps this is what you mean by sorting property names:

$mailbox=Get-MailBox testuser
foreach($name in $mailbox.psbase.PropertyNames|sort){ @{$name=$mailbox[$name]}}

Free Windows Admin Tool Kit Click here and download it now
July 9th, 2012 9:01pm

Here is my take on it, I would first use get-member to get the properties all sorted and then use foreach to iterate through them. I use -join to put the end result on the same line. Here is the code:

$mailbox = Get-MailBox JaapBrasser
$mailbox | get-member -membertype property | sort name | % {($_.name,$mailbox.$($_.name)) -join " : "}

July 9th, 2012 9:32pm

Nice work Jaap!

Slight modification and I get output almost identical, including the multi-value fields.

$mailbox = Get-Mailbox username;
$mailbox | gm -MemberType Property | %{ ("{0,-39}" -f $_.Name) + ": " + $mailbox.($_.Name) }

Thanks again all,

Joe

Free Windows Admin Tool Kit Click here and download it now
July 9th, 2012 10:14pm

I know this is an old thread, but for those who find it by googling...

I have often found that when I cannot sort a list, if I stream the output as a string, I can.

In this situation, this will give a sorted list of all the properties:

get-Mailbox -Identity username | select * | Out-String -Stream | sort

I hope someone finds this useful.

  • Marked as answer by JoeGasper Thursday, April 10, 2014 4:21 AM
April 9th, 2014 12:13pm

Hi, Brandon.

your solution seems to be the easiest way, but in Exchange 2013 it doesn't work. When I type 

get-Mailbox -Identity username | select * | Out-String -Stream | sort

It sort all rows one by one. So when user has a certificate, user certificate property divides in multiple rows and each row (it starts with a space) is sorted by its own. Thereby rows starting with a space are placed in the very beggining.

By the way this solution doesn't work either.

$mailbox = Get-Mailbox username;
$mailbox | gm -MemberType Property | %{ ("{0,-39}" -f $_.Name) + ": " + $mailbox.($_.Name) }

It returns

System.Byte[] System.Byte[]

Instead of certificate hash...

Free Windows Admin Tool Kit Click here and download it now
June 1st, 2015 5:28am

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

Other recent topics Other recent topics