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
}
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
}