Bulk add email alias to all AD user accounts

Joshua Lance 56 Reputation points
2023-09-26T20:32:11.75+00:00

We are preparing to change our domain name. The first step is to add an email alias to all user accounts. We use Azure AD Connect to sync our AD accounts with M365.

I need to add an email alias to all our users.

example:

Primary: ******@domain1.com

Alias: Add ******@domain2.com

The alias should be based on the existing user account... In the example, user1@.

I am hoping that I don't have to edit each user account proxy address individually.

Thanks.

Windows for business Windows Client for IT Pros Directory services Active Directory
Microsoft 365 and Office Install, redeem, activate For business Windows
Microsoft Security Microsoft Entra Microsoft Entra ID
{count} votes

Accepted answer
  1. Brian Zarb 1,685 Reputation points
    2023-09-26T20:44:32.2466667+00:00

    The below should help you out, fix as you will!

    If you find this helpful, please mark it as the answer, Regards Bz

    #Get all Ad users
    $users = Get-ADUser -Filter * -Properties EmailAddress, proxyAddresses
    
    #loop through each user
    foreach ($user in $users) {
        $newAlias = $user.EmailAddress -replace '@domain1.com', '@domain2.com'
        
        # Update the proxyAddresses attribute
        Set-ADUser $user -Add @{proxyAddresses = "smtp:$newAlias"}
    }
    # Check the updated proxyAddresses for a specific user
    (Get-ADUser -Identity 'User1' -Properties proxyAddresses).proxyAddresses
    
    #Sync up with Azure AD
    Start-ADSyncSyncCycle -PolicyType Delta
    
    
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Brian Zarb 1,685 Reputation points
    2023-09-27T10:37:29.84+00:00

    Here you go:

    # Get a specific AD user by their username
    $user = Get-ADUser -Identity 'User1' -Properties EmailAddress, proxyAddresses
    
    # Generate the new email alias
    $newAlias = $user.EmailAddress -replace '@domain1.com', '@domain2.com'
    
    # Update the proxyAddresses attribute for that user
    Set-ADUser $user -Add @{proxyAddresses = "smtp:$newAlias"}
    
    # Check the updated proxyAddresses for the specific user to verify
    $updatedUser = Get-ADUser -Identity 'User1' -Properties proxyAddresses
    
    $updatedUser.proxyAddresses
    
    #Sync up the AD (optional)
    Start-ADSyncSyncCycle -PolicyType Delta
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.