Create Exchange 2010 Individual Inbox Reports with PowerShell

In a previous article I demonstrated how to create Exchange 2010 Mailbox size reports with PowerShell. In that article we looked at usage data from the top level, such as a mailbox database. In this article, we’ll drill down a bit further into the mailbox itself and look at using the Get-MailboxFolderStatistics cmdlet to report on details of a single mailbox.

As before, I’m going to use the Exchange 2010 PowerShell Management console installed on my Windows 8 computer. Using the local management tools is really the best choice. As you might expect, Microsoft Exchange is a complex product when it comes to PowerShell, and using traditional PowerShell remoting is not as simple as you might think. Initializing the Exchange environment for a PowerShell session requires a lot of moving parts, which is why I find it easiest to install the management tools locally – I think you’ll have less opportunities for failure.

MailboxFolder Statistics

The cmdlet we’re going to be using is called Get-MailboxFolderStatistics. Let’s see how it works with my mailbox on my test Exchange 2010 server. By the way, the Exchange Information Store service must be running for these commands to succeed so if you try the commands and get no results, check the service.

[PS] C:\> get-mailboxfolderstatistics jeffhicks

You can use either the mailbox name or alias. You can also use Get-Mailbox and pipe it to Get-MailboxFolderStatistics. As you see below in Figure 1, the cmdlet generates a lot of information.
cmdlet Get-MailboxFolderStatistics
What you are actually seeing is information from a variety of folders in my mailbox. Let’s select a subset of properties to make this easier to visualize.

[PS] C:\> get-mailboxfolderstatistics jeffhicks | Select name,ItemsinFolder,*Size

This is a bit easier to understand now, as you can see in Figure 2.
cmdlet Get-MailboxFolderStatistics
You can control the scope of statistics by using the –FolderScope parameter.

[PS] C:\>get-mailboxfolderstatistics jeffhicks -FolderScope Inbox | Select Name,FolderSize

FolderScope values
The default value is All. The other values can come in handy for troubleshooting, but for reporting purposes I’m only concerned about the inbox. As you see below in Figure 3, I am now only looking within my inbox.
cmdlet mailbox Statistics

Data and Reports are subfolders within my Inbox. On one hand, Exchange has nicely formatted the values, but on the other, I like the raw values so I can do more with them. I can get the total size from the FolderandSubfolderSize property, but this too is a cooked value.

[PS] C:\>$inbox = get-mailboxfolderstatistics jeffhicks -FolderScope Inbox
[PS] C:\>$inbox[0].FolderAndSubFolderSize
562.2 KB (575,664 bytes)

By the way, $inbox is an array of three elements, the first element being the Inbox. Looking at this property in Get-Member confirms my suspicions (based on the first article in this series on Exchange 2010 mailbox reports) that I can convert this value.
cmdlet mailbox Statistics
Let’s try.

[PS] C:\>$inbox[0].FolderAndSubFolderSize.tobytes()
575664
[PS] C:\>$inbox[0].FolderAndSubFolderSize.tokb()
562

Excellent! This means I can get a report in a more meaningful or useful value.

[PS] C:\>get-mailboxfolderstatistics jeffhicks -folderscope Inbox | Select -first 1 Identity,ItemsinFolderandSubFolders, @{Name="Size";Expression={$_.FolderandSubFolderSize.toBytes()}}

cmdlet mailbox Statistics
This works great for the inbox. But let’s step back a bit and get usage for the entire mailbox with a command like this:

[PS] C:\> get-mailboxfolderstatistics jeffhicks | Select -first 1 Identity,ItemsinFolderandSubFolders,
@{Name="Size";Expression={$_.FolderandSubFolderSize.tobytes()}}


All I’ve done is rerun the command, but this type gets all items (although I only need the first one, which has data on the top of the information store as you see in Figure 6).
cmdlet mailbox Statistics
The size value is in bytes. I could have used the FolderandSubFolderSize.toMB() method, but that rounds the value to 3. If I need something in MB but a bit more granular, I can get the value in bytes and then divide by 1MB. I’ll use the .NET [math] class to round the result to two decimal places.

[PS] C:\> get-mailboxfolderstatistics jeffhicks | Select -first 1 Identity,ItemsinFolderandSubFolders, @{Name="Size";Expression={ [math]::Round($_.FolderandSubFolderSize.tobytes()/1MB,2)}}

cmdlet mailbox Statistics
To get a breakdown, say, between Inbox, Deleted Items, and Sent Items is a bit more complicated. Unfortunately, the –FolderScope parameter can only take a single value, so we have to get everything and filter for the items we want. Here’s a block of Powershell code that would work best in a script.

get-mailboxfolderstatistics jeffhicks |
where {$_.name -match "Inbox|Deleted|Sent"} |
Select @{Name="User";Expression={
(Split-Path $_.Identity -Parent)}},
@{Name="Folder";Expression={Split-Path $_.Identity -Leaf}},
@{Name="Items";Expression={$_.ItemsinFolderandSubFolders}},
@{Name="Size";Expression={$_.FolderandSubFolderSize.tobytes()}}

When executed against my mailbox I get a nice result as you can see below.
cmdlet mailbox Statistics
 
I hope this gives you some ideas on how to report on an individual mailbox. Naturally, I assume you are interested in applying these techniques to multiple mailboxes. In my next article I’ll demonstrate how to scale out with these ideas.