Using PowerShell to Retrieve Exchange Mailbox Statistics for Office 365 Migrations

Recently, I've been working on trying to finish up a migration from Exchange Server 2010 to Office 365. There are potentially numerous mailboxes that aren't used and those won't be migrated to Office 365 because there's no sense in paying for licensing for them.

How do you determine what mailboxes are in use?

First, use implicit remoting to load the Exchange cmdlets locally. Years ago, I would install the Exchange cmdlets locally, but it was brought to my attention that it's unsupported, at least according to this article: Directly Loading Exchange 2010 or 2013 SnapIn Is Not Supported.

1$Cred = Get-Credential
2$PSSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://<ExchangeServerFQDN>/PowerShell/ -Authentication Kerberos -Credential $Cred
3Import-PSSession -Session $PSSession

Next retrieve a list of all mailboxes with Get-Mailbox and pipe those results to Get-MailboxStatistics. I've silenced any warnings, otherwise the output may be littered with warnings for users who have never logged into their mailbox. Sorting the results by LastLogonTime in descending order places the most recently accessed mailboxes at the top of the list. Since I'm returning more than four properties and I want them in a table, I'll pipe to Format-Table and specify the properties I've found to be the most useful.

1Get-Mailbox -ResultSize Unlimited |
2Get-MailboxStatistics -WarningAction SilentlyContinue |
3Sort-Object -Property LastLogonTime -Descending |
4Format-Table -Property DisplayName, ItemCount, TotalItemSize, Last*

Specifying Last* for one of the properties returns the LastLoggedOnUserAccount, LastLogoffTime, and LastLogonTime. LastLogoffTime may not always be accurate or populated. At first, I thought the results were inaccurate due to an old account showing up with a recent LastLogonTime. The LastLoggedOnUserAccount for that account showed that someone else was accessing it which made more sense.

µ