Recently I had a customer need to remove an old domain from 365 as they no longer needed it. Using the portal you’d have to remove any alias individually so here’s a bit of powershelgl to automate this.
Here’s the bits you need to connect to 365 via Azure Powershell if you’re in Europe (in Order)
1) $UserCredential = Get-Credential
2) $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
3) Import-PSSession $Session
4) $Records = Get-mailbox -ResultSize Unlimited| where {$_.emailaddresses -like “smtp:*@domain.com”} | Select-Object DisplayName,@{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_ -like “smtp:*domain.com”}}}
foreach ($record in $Records)
{
write-host “Removing Alias” $record.EmailAddresses “for” $record.DisplayName
Set-Mailbox $record.DisplayName -EmailAddresses @{Remove=$record.EmailAddresses}
}
Simon Treadaway
Latest posts by Simon Treadaway (see all)
- Add replicas on Exchange 2010 Public Folders - 25/08/2016
- Remove all aliases for a domain in Office 365 - 24/08/2016
- Installing Exchange 2010 SP3 Rollups on Server 2012 - 12/07/2016