How to speed uo Get-Mailbox cmdlet RRS feed

  • Question

  • Hi,

    I m trying to count mailboxes in each mailbox database .

    I m running the following cmdlet in foreach loop iterating for 24 mailbox databases

    $mailbox_count = @((Get-Mailbox -Database $mailbox_database_name -resultsize unlimited)).Length

    It is consuming around 5 mins for completing the foreach loop.

    Is there a way to speedup this cmdlet or it there any alternate way to get mailbox count?

    If i select only Name to retrieve , does that help? but i didn't see any difference in execution time, it is same


    $mailbox_count = @((Get-Mailbox -Database $mailbox_database_name -resultsize unlimited | select Name)).Length



    Tuesday, August 8, 2017 8:15 PM

All replies

  • get-mailbox -resultsize unlimited | Group-Object -Property:database | Select-Object name, count

    I use the above and get the name of the database and # of mailboxes

    Tuesday, August 8, 2017 8:32 PM
  • "Select" is a client-based operation, the full set of object properties has already travelled the wire. The proper way would be to use Invoke-Command against remote PowerShell session and put the select inside the script block, so that only the properties you specify there are returned.
    Wednesday, August 9, 2017 7:11 AM
  • Does this Invoke-Command help to reduce the execution time if retrieving DB mailbox count in the same local exchange mailbox server where it is executing?
    Wednesday, August 9, 2017 8:35 AM
  • For a local execution, probably not big difference. I only have a handful of mailboxes so cannot really measure the difference...

    Wednesday, August 9, 2017 11:28 AM