Skip to main content

Office365: Removing all Exchange aliases from user accounts - moving from/to O365

In order to remove the domain form the Office365 subscription,  you need to delete all aliases.
There are many articles on the subject, how to remove one alias, but no data about how to remove ALL aliases from ALL accounts.
This little script will help you when you need to move to another O365 tenant or from cloud to on premises Exchange.

$alias = Get-Mailbox -resultsize unlimited

foreach($x in $alias)
{
$x.emailaddresses = $x.userprincipalname
Set-mailbox $x.alias -emailaddresses $x.emailaddresses
}