Share via


How to Use Get-MailboxStatistics Cmdlet?

Microsoft Exchange Server has a lot of great tools, such as the Exchange Management Shell (EMS) – a command-line interface that allows automation of administration tasks in Exchange Server. The PowerShell commands provide more detailed information and help to administer, configure, and maintain the Exchange Server system.

One of these commands is the Get-MailboxStatistics which we will be covering in detail in this article. This command is important to any Exchange Server administrator as it helps to get vital information about a mailbox, such as the size of the mailbox, number of messages it contains, and the last accessed time. The command gives information about the whole history of the mailbox, such as move requests, move reports, etc.

This command applies to locally installed versions of Exchange Server as well as Exchange Online in Office 365 or Microsoft 365 tenant.

On its own, if you run it against a mailbox, it will give minimal information, such as Display Name, Item Count, Storage Limit Status (if applicable), and last logon time.

The complete command is as follows:

Get-MailboxStatistics -Identity "<mailbox name>"

The command can also give more information about your mailbox. To get full information of your mailbox, you can run the command by appending the | FL to the command (see the example below).

Get-MailboxStatistics -Identity "<mailbox name>" | FL

This will give all the information about a mailbox. You can narrow down this information and be selective of what needs to be displayed. Although you might never use this information, it’s a good way to return all the information you can display and to know all the possible parameters when in doubt.

To show only the information that you need, you can use the command, as given below, by using | Select-Object <object name> parameter.

Get-MailboxStatistics -Identity "<mailbox name>" | Select-Object <parameter>

This will display only the parameter that you specify. If you would wish to add more parameters, you can do so by separating the parameters with a comma.

Get-MailboxStatistics -Identity "<mailbox name>" | Select-Object <parameter>, <parameter>

This will allow you to add a lot of parameters.

If you need to export to a Comma Separated Value (CSV) file for analysis or other purposes, add the | Export-CSV <filepath> parameter (see the example below).

Get-MailboxStatistics -Identity "<mailbox name>" | Select-Object <parameter> | Export-CSV <filepath>

This will export a CSV file with all the results that will be returned by your command and parameter selection. If the folder where you will be exporting doesn’t exist, you need to create it manually as it doesn’t create the folder automatically.

So, to get the information of every mailbox, you can create a loop that goes through all the users in the mailboxes. But if you are exporting to a CSV file, it will not work that well. To get all the information about a particular database, you need to run the command as given below.

Get-MailboxStatistics -Database "Mailbox Database"

This will go through all the mailboxes and system mailboxes in the database specified. You can use the include method and CSV export as well (see the example below).

Get-MailboxStatistics -Database "<mailbox database>" | Select-Object <parameter> | Export-CSV <filepath>

You can also use the combination of the Get-MailboxDatabase and Get-MailboxStatistics to retrieve the information needed from all the mailbox databases in your Exchange Server setup. This command can be used, along with all the parameters.

Get-MailboxDatabase | Get-Mailbox Statistics

With the Get-MailboxStatistics command, you can also filter your results. For example, if you need to only retrieve information of all the mailboxes except disconnected mailboxes, you can use the | Filter, along with Disconnectdate and operators with ne (which means not equal). If you want to show only the disconnected mailboxes, you can use the eq (which means equal).

Get-MailboxDatabase | Get-MailboxStatistics -Filter 'DisconnectDate -ne $null'

The above command will go through all the mailbox databases mounted in your Exchange Server setup and retrieve the information only of the mailboxes which are not disconnected.

If you are looking into getting a report or history of the moves that the mailbox has done, you can use the -IncludeMoveHistory or the -IncludeMoveReport parameter to the command.

Get-MailboxStatistics -Identity <mailbox name> -IncludeMoveHistory | Format-List

Apart from getting all the information of the mailbox, this parameter will also retrieve the Move History of the mailbox, which will be on top of the attributes.

Get-MailboxStatistics -Identity <mailbox name> -IncludeMoveReport | Format-List

To Wrap Up

As you can see, the command Get-MailboxStatistics gives all the information about mailboxes and mailbox database. However, this is only applicable if Exchange database is mounted.