Use Powershell to remove aliases from O365 users

First blog of the new year! Let me start off by wishing everyone a great 2016!

A quick blog this time. One of my clients sold a part of their company and needed to hand over the domain they currently use in Office 365. So, for all users I needed to remove the alias ending on this domain. Of course, PowerShell is the tool for the job.

We need to remove the alias from the EmailAddresses property of the users, using the set-mailbox cmdlet. In full:

$mailboxes = get-mailbox -resultsize unlimited
Foreach ($mbx in $mailboxes) {
$name = $
$suffix = ''
$address = $name + $suffix
Set-mailbox $name -emailaddresses @{remove=$address}}

So yet again, be it Office 365, Azure, or on-prem: PowerShell is the way to go!