What to say about Reverse Directory Synchronization… I should probably start this post off with answering some basic questions, like, “Why would I do this?” “What are the basic pieces to get it working?” “Do I like smashing my head into a wall?” and most importantly, “Why would I do this… TO MYSELF!?” But that is boring… So I’ll get to it later.

For now, you should know that the ‘adventure’ we are about to embark upon is full of pitfalls and laden with the corpses of lesser IT engineers… Many an engineer ran a script, botched the group setup, and completely destroyed access to an integral system, and for what? So that they could have AD managed DLs. So I have to ask the question, Are you a bad enough dude to save the pres… I mean… Are you a bad enough dude to break the whole of your AD? Cool, then let’s do this!

For starters, we will need to gather some information. Basically you will want to find out all the users, the groups, the contacts, the resource mailboxes, and the domains. These are important if you want to manage them locally because you’ll need to collect the data from them and assign them to a local resource.

Luckily for you, I’ve developed a neat little script that will do that for you:

#UserMailbox data collection
$userMailboxes = Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited
$emailCountFinal = 0
foreach ($userMailbox in $userMailboxes) {
    $emailCount = $userMailbox.emailAddresses.count
    if ($emailCount -gt $emailCountFinal) {
        $emailCountFinal = $emailCount
        $offendingMailbox = $userMailbox.displayName
$userMailboxesCSV = $userMailboxes | select displayName, emailAddresses, office
#Contact data collection
$contacts = Get-MsolContact
$contactsCSV = $contacts | select displayName, emailAddress
#Room Mailbox data collection
$roomMailboxes = Get-Mailbox -RecipientTypeDetails RoomMailbox -ResultSize Unlimited
$roomMailboxesCSV = $roomMailboxes | select displayName, emailAddresses, moderatedBy
#Equipment Mailboxes data collection
$equipmentMailboxes = Get-Mailbox -RecipientTypeDetails EquipmentMailbox -ResultSize Unlimited
$equipmentMailboxesCSV = $equipmentMailboxes | select displayName, emailAddresses, moderatedBy
#Group Data collection
$groups = Get-Group | ? { $_.windowsEmailAddress -notlike '' }
$groupsCSV = $groups | select displayName, windowsEmailAddress, Members, ManagedBy
$domains = Get-MsolDomain
$domainsCSV = $domains | select name
Write-Host -ForegroundColor Green "You have $($userMailboxes.count) User Mailboxes."
Write-Host -ForegroundColor Green "User $offendingMailbox has the most email addresses at $emailCountFinal ."
Write-Host -ForegroundColor Green "You have $($contacts.count) contacts."
Write-Host -ForegroundColor Green "You have $($groups.count) groups."
Write-Host -ForegroundColor Green "You have $($roomMailboxes.count) Room Mailboxes."
Write-Host -ForegroundColor Green "You have $($equipmentMailboxes.count) Equipment Mailboxes"
Write-Host -ForegroundColor Green "You have $($domains.count) domains associated with your Office 365 account."
Write-Host -ForegroundColor Green "The above information has been expounded upon in CSVs in this directory."
$userMailboxesCSV | Export-Csv -Path .\Users.csv -NoTypeInformation
$contactsCSV | Export-Csv -Path .\contacts.csv -NoTypeInformation
$roomMailboxesCSV | Export-Csv -Path .\rooms.csv -NoTypeInformation
$equipmentMailboxesCSV | Export-Csv -Path .\equipment.csv -NoTypeInformation
$groupsCSV | Export-Csv -Path .\groups.csv -NoTypeInformation
$domainsCSV | Export-Csv -Path .\domains.csv -NoTypeInformation

Now you can safely say you’ve collected all the crap you are interested in… Actually there might be more, but uh… Anyway, good luck with that. This also gives you a static snapshot of your Office 365 environment, so that is pretty cool. Anyway, I’ll continue the pain and torture in the next post, as we… COLLECT THE EMAIL ADDRESSES AND WRITE THEM TO YOUR ACTIVE DIRECTORY!!!!!! (That was supposed to be read in one of those echo…y…? announcer voices… Because things.)

This is part of a five part series!

Part 1
Part 2
Part 3
Part 4
Part 5

Leave a Reply

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