Count Mailboxes in all Exchange Databases (October 23 2014)
I was looking for a quick way to return the total count of mailboxes in each one of my Exchange 2013 databases. I jumped on google and came up with this line on several sights.
(get-mailboxdatabase) | foreach-object {write-host $_.name (get-mailbox -database $_.name).count}
At first glance it looked good. Except it doesn’t work. As running it will return the all too familiar error.
WARNING: By default, only the first 1000 items are returned.
Use the ResultSize parameter to specify the number of items returned.
To return all items, specify “-ResultSize Unlimited”.
Be aware that, depending on the actual number of items, returning all items can take a long time and consume a large amount of memory.
Also, we don’t recommend storing the results in a variable.
Instead, pipe the results to another task or script to perform batch changes.
To fix this I simply modified the command per the errors instructions.
(get-mailboxdatabase) | foreach-object {write-host $_.name (get-mailbox -database $_.name -ResultSize Unlimited).count}
Nice and simple.