Preparing your Exchange migration Part 3 – The cleanup

For large Exchange systems, this will probably be the largest undertaking that will take the most time to accomplish. The tasks involved here will cover pretty much every skillset from Exporting and reviewing accounts and information to working with different business units to determine usage and then finally backing up and deleting accounts…For this cleanup your tools PowerShell and Excel will be your best friend. Once you are done the 3 step process of cleaning up Exchange you will be better prepared to make the most of your Office 365 (Exchange) migration while licensing only what you need to keep. If you have any new employees that you want to train up, this exercise is a really good one to help them get to know the Exchange system.

Exporting your data

The first step here will be performed with PowerShell. You are going to want to run a full export of your Exchange mailbox environment, basically to allow you to review anything that can cost you money in Exchange online. The first Export we will perform will be all of your mailboxes and put them into an Excel spreadsheet

get-mailbox -resultsize “unlimited” | sort displayname | select-object Name, Alias, UserPrincipalname, RecipientTypeDetails | export-csv c:\Exchange_cleanup\mailboxes.csv

You will end up with something like this


Next we will get some mailbox statistics, for this you will use a different PowerShell command pulling out different statistics.

Get-Mailbox -resultsize “unlimited” | Get-MailboxStatistics | Sort displayname | select-object displayname, totalitemsize, itemcount, lastlogontime| export-csv c:\Exchange_cleanup\mailboxstats.CSV

The output will give you something like this


Now for some Excel Magic, you can merge the two CSV files and turn it into a cool Excel spreadsheet, now just add tables with headers and you can filter on different fields. You now have the tool you will use for the remainder of this project which might look something like this.

Merged Table

A word on FT vs. Select-Object in PowerShell

I used to use Format Table or FT for everything when running PowerShell, if gives you a nice little formatted table. I did this right up until I wanted to export data off of the screen. Format Table does not work with export-CSV. Well, that’s not true, it does work…It just doesn’t give you the information you are looking for. If you export to CSV a formatted table it gives you the actual formatted able information which might look something like this

formatted table

Not very useful, I now use select-object cmdlet which works nicely and gives you the same information.

What do I do with this?

You now have a lot of information you can use to run through to start your Exchange cleanup. Two things I like to filter and focus on are LastLogonTime and RecipientTypeDetails. The Recipient Details will help me determine if any user mailboxes can be converted into shared mailboxes thus freeing up or not costing licenses when we migrate to Office 365. The Last Logon time will allow me to cleanup any stale mailboxes, I am going to go after anything that hasn’t be accessed for awhile or haven’t been accessed at all.

Now you can start to mark mailboxes for disabling or deletion, but before you do that backup the mailboxes into PST…just in case.

To do this you will want to take the email address or alias fields from your main spreadsheet and put them in a single column then use the following commands

Import-CSV C:\cleanup\uvwz1.csv | ForEach {Get-Mailbox -Identity “$($_.Name)”} | Select Alias | Export-CSV C:\cleanup\alias\uvwz2.csv

foreach ($mbx in (Import-Csv C:\cleanup\alias\uvwz2.csv)) { New-MailboxExportRequest -Mailbox $mbx.Alias -FilePath “\\helpdesk01\cleanup\$($mbx.Alias).pst” }

This will help you batch backup your mailboxes before you delete them, depending on the load you might want to break these up into smaller files.

Tips around mailbox cleanup

  • Don’t attempt a mailbox cleanup or conversion without consulting the business, you may end up deleting things that are still in use and angering people. It’s worth the time to consult the business and it’s a good touch point especially for those that aren’t used to working with other people…new skills.
  • Be aware of the different between disable and remove when deleting Exchange mailboxes. Disable will mark the mailbox for deletion, remove will delete the mailbox and the Active Directory user.
  • Be a team player and spread the love. You might not want to attempt this whole thing yourself but trust me…involve your team.

Once this is all said and done, the odds are you might come out of this the hero. Let’s do some simple math. Say in a system of 3000 mailboxes, you were able to cleanup 10% by converting the shared mailboxes or deleting. When you migrate to Office 365 you will have saved your company in an E3 subscription

300 mailboxes x $25.50 x 12 months = $91 800/year

That’s not a small amount.


Leave a comment

Your email address will not be published.