I thought I’d share a useful little powershell trick I used today which allowed me to easily compare two very similar mailboxes in Office 365. I had a user who had a duplicate mailbox which had been inadvertently created through an issue with AAD Sync. I knew all the fields I would be comparing would be identical so I used a hash table with embedded arrays to compare the information I was interested in.

First create a variable for each mailbox which will contain all the information we will be comparing. Then create the hashtable.

Next pipe the fields from the variable into the hash table, creating an array for each one. Then pipe the variables containing our mailbox data into the nested arrays in the hashtable.

Finally I converted the hashtable back to a PSObject so that I could export it to a csv file and analyse the output in Excel.