[Thanks to Greg Hall for assisting me with this!]
We recently underwent a corporate name change, which required us to migrate our users over to email addresses on the new domain.
Because most users still require access to their old account, I was unable to remove those mailboxes, which created confusion for the majority of users who pull from the Global Address List, which displays all mailboxes on our corporate Office365 account. Despite a change in the naming convention from <first initial><lastname> to <firstname>.<lastname>, folks were still sending plenty of email to old user mailboxes, thwarting our efforts to wean them away.
Initially I sought to segregate the old domain from the new using Address Book Policy, but found we had not defined certain parameters upon which New-AddressBookPolicy is dependent. So, moving away from that approach, and with the help of Greg Hall, I decided to simply hide the old mailboxes from the Global Address List - which worked perfectly. Here's how I did that . . .
Connect to Office365 using the Azure Active Directory Module, then input:
Get-User -Filter {Company -eq 'Microsoft'} | Get-Mailbox -resultsize unlimited | Set-Mailbox -HiddenFromAddressListsEnabled $true
And don't forget your Distribution Groups!
Export the list of group names to .CSV and input the following:
Get-Content -Path C:\LocationOf.CSV | Set-DistributionGroup -HiddenFromAddressListsEnabled $true
Bam. Done.
Of course, we had not defined the "Company" value in our users' Exchange properties, but I'll discuss using PS to edit Exchange properties in another post.