Learn Exchange the Guru way !!!


Count Powershell output

Question – How many exchange servers in your organization? Easy to count?Ok, then how many Equipment and room mailboxes in your organization? Well, you know how to get the list but how to count them real quick?

This is a quick powershell tip. Let’s take an example

The cmdlet: Get-ExchangeServer will return the list of all exchange servers in the organization.

Now try this:

[PS] C:\Documents and Settings\ratish>Get-ExchangeServer | measure-object

Count : 62
Average :
Sum :
Maximum :
Minimum :
Property :

Now, this includes all of them – E2K, E2K3, E2K7 all of them… You could distinguish by looking at the AdminDisplayVersion value.

Let’s take another example:

This one returns all Equipment mailboxes:

Get-Mailbox -ResultSize Unlimited | where {$_.ResourceType -eq “Equipment”}

If you wanna count it, add the Measure-Object switch.

Get-Mailbox -ResultSize Unlimited | where {$_.ResourceType -eq “Equipment”} | measure-object

Another one perhaps:

This one returns the count of all mailboxes on a specific server:

Get-Mailbox -ResultSize Unlimited | where {$_.ServerName -eq “SERVERNAME”} | measure-object

Now, remember that the “Measure-Object” switch is something which counts the lines in the output and gives results.

Ratish Nair
MVP Exchange
Team @MSExchangeGuru

Keywords: Count exchange powershell output, how to count powershell, get count for powershell output

5 Responses to “Count Powershell output”

  1. Ron Says:

    Good one Ratish. Thank you.

  2. Nuno Mota Says:

    A method that I normally use is to run the commands like this:

    (Get-Mailbox -ResultSize Unlimited).Count

    for example, which will just return an integer with the number of objects found. I find this useful in scripts!

  3. Jeevananthan Says:

    how to email this mailbox count from server to my mailbox through script.

  4. Nuno Mota Says:

    You can do something like this (not tested!):
    Send-MailMessage -From “” -To “” -Subject “Mailbox Count” -Body $((Get-Mailbox -ResultSize Unlimited).Count) -SMTPserver “” -DeliveryNotificationOption onFailure

  5. Jim Says:

    Thank you. In my case I wanted to be able to get it down to just an integer with Select-Object (found after some googling) so I could subtract it from my total mailbox count. First system mailboxes then disconnected mailboxes:
    Get-MailboxStatistics -Database dbname | where {$_.DisplayName -match “System”} | Measure-Object | Select-Object -expand Count
    Get-MailboxStatistics -Database dbname | where {$_.DisconnectDate -ne $null} | Measure-Object | Select-Object -expand Count

Leave a Reply




Do NOT follow this link or you will be banned from the site!