Get Mailbox Folder Size

Article - Get Mailbox Folder Size from Exchange using PowerShell (morgantechspace.com)

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.

1
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.

1
2
Get-MailboxFolderStatistics "AlexW@contoso.com" |`
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. 

1
2
Get-MailboxFolderStatistics "AlexW@contoso.com" |`
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.

1
2
Get-MailboxFolderStatistics "AlexW@contoso.com" -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.

1
2
3
Get-MailboxFolderStatistics "AlexW@contoso.com" -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.

1
2
Get-MailboxFolderStatistics  "Admin@contoso.com" -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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$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

No comments: