How to Use Get-MailboxFolderStatistics in Powershell

How to Use Get-MailboxFolderStatistics in Powershell

Running and managing a massive Exchange server can be exhausting and challenging, mostly for people who work in large organizations.

Getting a full list of all the user mailboxes would be challenging without the help of PowerShell.

Fortunately, there is a way to make all this data visible by using a command: Get-MailboxFolderStatistics.

In this blog post, we’ll show you how to use Get-MailboxFolderStatistics in PowerShell efficiently to get each parameter from user mail boxes.

What is Get-MailboxFolderStatistics in PowerShell?

The Get-MailboxFolderStatistics is a cmdlet command available on the on-premises exchange and the cloud-based service.

This cmdlet can be used to retrieve information from all the subfolders and folders of a mailbox, regardless of the folder type.

By using Get-MailboxFolderStatistics, administrators can retrieve all the parameters they need from a mailbox.

This automates an otherwise time-consuming process, as retrieving items from an inbox folder manually can take a lot of time.

The syntax of Get-MailboxFolderStatistics is the following:

Get-MailboxFolderStatistics

   [-Identity] <GeneralMailboxOrMailUserIdParameter>

   [-Archive]

   [-DiagnosticInfo <String>]

   [-DomainController <Fqdn>]

   [-FolderScope <ElcFolderType>]

   [-IncludeAnalysis]

   [-IncludeOldestAndNewestItems]

   [-IncludeSoftDeletedRecipients]

   [-ResultSize <Unlimited>]

   [-SkipCount <Int32>]

   [-UseCustomRouting]

   [<CommonParameters>]


Each one of these switches and parameters comes with a default value that can be modified before running the command:

  • Identity: Identify specifies the precise mailbox from which you want to retrieve the information. It could be the mailbox of one user or multiple users;
  • Archive: Archive provides the cmdlet with the information it needs to retrieve info for an archive mailbox if it’s associated with the primary mailbox;
  • DiagnosticInfo: This parameter provides additional diagnostic information if necessary, and it can be used to troubleshoot errors;
  • DomainController: DomainController specifies a FQDN if necessary;
  • FolderScope: FolderScope shows the type of folder that will return the output;
  • IncludeAnalysis: This parameter is used if it’s necessary to run additional analytics of the individual mailbox;
  • IncludeOldestandNewestItems: Specifies whether it’s necessary to include the oldest and newest calendar items in the analysis or not;
  • IncludeSoftDeletedRecipients: Specifies whether to include soft-deleted recipients in the statistics;
  • ResultsSize: ResultsSize shows the total size of the data returned by the command. By default, there is no limit for this parameter when it comes to returning results;
  • SkipCount: SkipCount is used to skip certain items in the final item count;
  • UseCustomRouting: Specifies whether to use custom routing or not;
  • CommonParemeters: Includes other commonly used parameters in cmdlets.

Benefits of Using Get-MailboxFolderStatistics Cmdlet in PowerShell

Using the Get-MailBoxFolderStatistics cmdlet not only returns the number of items on a mailbox - it can also be the answer to perform certain tasks that would otherwise be manually performed.

Let’s look at some examples to understand how the Get-MailboxFolderStatistics can help you in your daily tasks within PowerShell:

  1. Obtain in-detail statistics for each folder within an Exchange mailbox;
  2. Identify storage use to see how much space each folder takes, which allows administrators to improve source allocation by measuring item size;
  3. Troubleshoot any possible error in the mailboxes, as the command can also perform error diagnosis;
  4. Recover deleted items inside soft-deleted mailboxes, which are no longer stored in the server but are still recoverable to view their information;
  5. Generate a CSV file with the folder size, items in folder, and other folder stats from users in an organization;
  6. Check out all the values and item counts contained inside a mailbox to make changes or assign further roles if necessary;
  7. Tailor specific organizational requirements by analyzing all the details returned regarding the total number of items contained within a mailbox.

Prerequisites to Use Get-Mailbox Folder Statistics Cmdlet

Before running any cmdlet in PowerShell, it is necessary to have the correct permissions and roles to do so. Otherwise, error messages will continue to pop out along the way.

According to the official Microsoft website, this is how you can check the required permissions to run the Get-MailBoxFolderStatistics cmdlet on PowerShell:

  1. Open PowerShell and log into your Microsoft account with administrator permissions;
  2. Run the following cmdlet on PowerShell: “$Perms = Get-ManagementRole -Cmdlet <Cmdlet>.” In this case, it’s necessary to replace <cmdlet> with Get-MailboxFolderStatistics;
  3. After running the command, PowerShell will show you the necessary roles, permissions, and requirements to run the Get-MailboxFolderStatistics command within your organization;
  4. Keep in mind that only administrators can provide you with the necessary permissions to run commands, so in case you are missing them, contact your organization manager for further assistance.

How to Use Get-MailboxFolderStatistics in PowerShell

We will use the Get-MailboxFolderStatistics command to view complete statistics from certain mailboxes within PowerShell.

In order to do this, we will connect to the Exchange Online PowerShell environment and run the cmdlet as requested. These are the three steps you need to follow to use Get-MailboxFolderStatistics in PowerShell.

Step 1: Connect to Exchange Online PowerShell

To run cmdlets, we first need to connect to the Exchange Online PowerShell environment managed by your organization.

To do so, launch PowerShell in your system, and run the following command:

Connect-ExchangeOnline -UserPrincipalName [email protected]


Replace “[email protected]” with your own email, and use your Microsoft account credentials to connect to Exchange PowerShell.

After connecting to PowerShell, and provided you have already checked the required permissions as mentioned above, we are ready to run cmdlets.

Step 2: Identify the User Mailbox

Perhaps the most important part of the Get-MailboxFolderStatistics cmdlet is the Identity parameter.

The identity parameter, as mentioned above, helps you identify the specific mailbox from which you want to obtain statistics and information.

Therefore, it will be crucial to identify the user mailbox you want to check before running the parameter.

Remember that you can use any specific value that identifies the mailbox, such as name, alias, email address, domain, username, and more.

Step 3: Run Get-MailboxFolderStatistics Cmdlet

Now, it’s time to run the Get-MailboxFolderStatistics cmdlet on PowerShell.

To understand how the command works, let’s take a look at a few examples. Open the command window, and run the following command:

Get-MailboxFolderStatistics -Identity Simon


This simple one-line command returns all the folder information from the user Simon. Since it doesn’t have any other parameters, it will simply return all the data within the mailbox without altering the final query.

Now, let’s look at this example:

Get-MailboxFolderStatistics -Identity "James" -FolderScope RecoverableItems -IncludeAnalysis


In this example, the cmdlet will identify James as the user from which you want to see the mailbox items.

Then, it uses the FolderScope switch to target only RecoverableItems, and the IncludeAnalysis switch to view the statistics of these items.

Alternatively, the Get-MailboxFolderCommand can be used to retrieve the complete archive of a mailbox:

Get-MailboxFolderStatistics -Identity [email protected] -Archive


The identifier used in this command is the email of the user. Then, the Archive switch asks the command to return a complete view of all statistics from James’s archive.

Summary: How to Use Get-MailboxFolderStatistics

Using the Get-MailboxStatistics cmdlet can bring answers to your problems, as it provides us with an easy way to view in-detail info about user mailboxes natively from PowerShell. Before running the command, consider the following factors:

  • By default, the Get-MailboxFolder statistics will return all mailbox items and statistics from desired mailbox unless given further parameters, such as Archive and FolderScope;
  • Only administrators and users with enough permissions can run the Get-MailboxFolderStatistics command in PowerShell;
  • If the command is not working, make sure to use the correct Identity switch, as it determines the outcome of the cmdlet.

FAQ

What is the Get-EXOMailboxFolderStatistics Cmdlet?

Get-EXOMailboxFolderStatistics is a cmdlet that is only available in the Exchange Online PowerShell Module whose purpose is the same as the Get-MailboxFolderStatistics: retrieve information about the folders in a specific mailbox. Both cmdlets have the same purpose - the difference lies in the environment they are available in.