Compare two CSV files to trend mailbox growth

I had an interesting request the other day. A co-worker had two CSV files containing mailbox information from the same Exchange server, but from different parts of the day. He wanted to know if there was any way to find which users had the most growth in their mailbox size.

Here is an example of how to get mailbox size for all users on the same Exchange server:

Get-MailboxStatistics -Server EXCHANGE01 | 
Select-Object -Property DisplayName, 
@{N="SizeMB";E={$_.TotalItemSize.Value.ToMB()}}, Identity | 
Export-Csv file2.csv -NoTypeInformation

The first thought that came to mind had involved Group-Object and Measure-Object. I threw something together that got the job done, but decided to clean it up a bit and thought I’d share it here.
[cc lang=”powershell”]
Import-Csv file1.csv, file2.csv | Group-Object -Property Identity | %{
$thisDetail = $_ | Select-Object -ExpandProperty Group| Measure-Object SizeMB -Maximum -Minimum
New-Object psobject -Property @{
DisplayName = [string]($_.Group[0].DisplayName)
GrowthMB = [float]($thisDetail.Maximum – $thisDetail.Minimum)
} | Select DisplayName, GrowthMB
} | Sort-Object GrowthMB -Descending | Select-Object -First 10
[/cc]

Hope someone else finds this helpful!

This entry was posted in Messaging, Scripting. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Notify me of followup comments via e-mail. You can also subscribe without commenting.