How to set a domain email alias for Office 365 users on a specific domain

Our forgettable business name, GCITS, is often written as GCIT. We don’t really mind this though sometimes this mistake extends into emails as well. Customers will occasionally try to raise a ticket via [email protected] instead of [email protected]

To solve this, we registered gcit.com.au and needed to apply it to all users that use either gcits.com or gcits.com.au as their primary email address. We don’t want it to apply to every user, just the ones that match that criteria.

The following procedure will add a domain alias to all users that match a specific criteria. For instance, the user [email protected] will get [email protected] added to it’s list of email addresses. This allows these users to receive email for the new address.

In order for this to work, you’ll need to have the new domain verified and set up in Office 365.

Here’s how to do it:

  1. Log into Exchange Online via Powershell. See our quick guide on how to do this – or just copy the entire code block with the Exchange Online connection cmdlets at the bottom of the page.
  2. Modify and run the following script to get all users with a primary smtp address matching the domain. Change “gcits.com” to your current domain:
    $users = Get-Mailbox | Where-Object{$_.PrimarySMTPAddress -match "gcits.com"}
    
  3. Modify the following script, replacing @gcit.com.au with the new domain:
    foreach($user in $users){
        Write-Host "Adding Alias $($user.alias)@gcit.com.au"
        Set-Mailbox $user.PrimarySmtpAddress -EmailAddresses @{add="$($user.Alias)@gcit.com.au"}
    }
    
  4. You’re done. You can run this to confirm that it worked:
    $users | ft PrimarySmtpAddress, EmailAddresses

 

Here’s the complete script with the Exchange Online connection cmdlets included:

$credentials = Get-Credential
Write-Output "Getting the Exchange Online cmdlets"
 
$Session = New-PSSession -ConnectionUri https://outlook.office365.com/powershell-liveid/ `
-ConfigurationName Microsoft.Exchange -Credential $credentials `
-Authentication Basic -AllowRedirection
Import-PSSession $Session

$users = Get-Mailbox | Where-Object{$_.PrimarySMTPAddress -match "gcits.com"}

foreach($user in $users){
    Write-Host "Adding Alias $($user.alias)@gcit.com.au"
    Set-Mailbox $user.PrimarySmtpAddress -EmailAddresses @{add="$($user.Alias)@gcit.com.au"}
}

Was this article helpful?

Related Articles