Get Mailbox Folder Size from Exchange using PowerShell

We can use the Exchange Powershell cmdlet Get-MailboxFolderStatistics to list all the available folders in a specific user mailbox or shared mailbox. This command also helps to get the size and no of items in every folder and subfolders.  This cmdlet is available for both on-premises Exchange and Microsoft Office 365 (Exchange Online) services. Before start, run the following command to connect Exchange Online module.

Connect-ExchangeOnline

The following command just extracts all the folders from the given user mailbox (ex: Alex) along with folder size and the number of items in the folder.

Get-MailboxFolderStatistics "[email protected]" |`
Select Name,FolderSize,ItemsinFolder

The above command individually returns folder and subfolder sizes, we need to select the field FolderAndSubfolderSize to get the size of the folder and subfolders. 

Get-MailboxFolderStatistics "[email protected]" |`
Select Name, FolderAndSubfolderSize ,ItemsInFolderAndSubfolders

We can get specific folder and subfolder details by using the -FolderScope parameter.  The following command lists the “Inbox” folder and all the subfolders that are created under the Inbox folder.

Get-MailboxFolderStatistics "[email protected]" -FolderScope Inbox |`
Select Name,FolderSize,ItemsinFolder

Instead of getting subfolder sizes individually for the Inbox folder, we can filter only the Inbox folder and select the field FolderandSubFolderSize which returns the entire Inbox folder size.

Get-MailboxFolderStatistics "[email protected]" -FolderScope Inbox |`
Where {$_.FolderPath -eq "/Inbox"} |`
Select Name,FolderandSubFolderSize,ItemsinFolderandSubfolders

Get Root or Non-IPM subtree folders

By default, the Get-MailboxFolderStatistics cmdlet returns IPM subtree (IntraPersonal Messaging) folders. The IMP subtree is a structure of folders intended to handle messages between human recipients, such as Inbox or Sent items.

Alon with IMP subtree folders, we will also have Root-level folders, also known as Non-IPM subtree (Non-Interpersonal Messaging). The Non-IPM subtree represents a hierarchy of folders at the root level used for storing special data and metadata created and consumed by different features and services such as Microsoft Teams private chat (1 to 1 chat). The copy of Team private chat messages will be stored in the special folder “TeamsMessagesData” (or TeamChatHistory) in the associated user mailbox. 

Run the following command to retrieve the Non-IPM subtree or Root level or special folders.

Get-MailboxFolderStatistics  "[email protected]" -FolderScope NonIPMRoot |`
Select Name,FolderSize,ItemsinFolder

Export Specific Folder Size for all Mailboxes

The following script retrieves the size of inbox folder of all user mailboxes in the organization.  The result will be exported to a CSV file.

$Result=@() 
$mailboxes =  Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited
$totalmbx = $mailboxes.Count
$i = 1 
$mailboxes | ForEach-Object {
$i++
$mbx = $_
$folderstats = Get-MailboxFolderStatistics $mbx.Identity -FolderScope Inbox | Where {$_.FolderPath -eq "/Inbox"}

Write-Progress -activity "Processing $mbx" -status "$i out of $totalmbx completed"
 
$Result += New-Object -TypeName PSObject -Property $([ordered]@{ 
Name = $mbx.DisplayName
UserPrincipalName = $mbx.UserPrincipalName
InboxSizeInMB = [math]::Round(($folderstats.FolderandSubFolderSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2)
InboxItems = $folderstats.ItemsinFolderandSubfolders })
}
 
$Result | Export-CSV "C:\InboxFolderSizes.csv" -NoTypeInformation -Encoding UTF8
Advertisement

1 thought on “Get Mailbox Folder Size from Exchange using PowerShell”

  1. What if the mailbox has over 1K folders or subfolders? Found one but can’t get a complete list from powershell, and get-mailboxfolderstatistics doesn’t seem to have an unlimited or recursive switch

    Reply

Leave a Comment