Forum Discussion

sunflower sunflower's avatar
sunflower sunflower
Copper Contributor
May 25, 2018
Solved

Powershell for replacing primary email address and adding current primary to alias email addresses

We use a hybrid O365 environment.  On-premise AD, using Azure AD sync, with all O365 mailboxes.   We have about 120 mailboxes where we need to change their primary email domain to a new domain and ...
  • VasilMichev's avatar
    May 28, 2018

    On-premises, you should be able to handle this via Email Address Policies: https://technet.microsoft.com/en-us/library/bb232171(v=exchg.150).aspx

     

    It's also possible via PowerShell, the easiest example would be by using the -WindowsEmailAddress parameter:

     

    Spoiler
    -WindowsEmailAddress

    The WindowsEmailAddress parameter specifies the Windows email address for this recipient. This is a common Active Directory attribute that's present in all environments, including environments without Exchange. Using the WindowsEmailAddress parameter on a recipient has one of the following results:

    • In environments where the recipient is subject to email address policies (the EmailAddressPolicyEnabled property is set to the value True for the recipient), the WindowsEmailAddress parameter has no effect on the WindowsEmailAddress property or the primary email address value.

    • In environments where the recipient isn't subject to email address policies (the EmailAddressPolicyEnabled property is set to the value False for the recipient), the WindowsEmailAddress parameter updates the WindowsEmailAddress property and the primary email address to the same value.

    The WindowsEmailAddress property is visible for the recipient in Active Directory Users and Computers in the E-mail attribute. The attribute common name is E-mail-Addresses, and the Ldap-Display-Name is mail. If you modify this attribute in Active Directory, the recipient's primary email address is not updated to the same value.

    Doing so will add the new primary SMTP address, while preserving the old one as secondary. Alternatively you can cook up a more complex function to check out each individual address and add/remove new ones as needed. I have some examples on how to do this here:

     

    https://www.michev.info/Blog/Post/2011/bulk-replacing-proxy-addresses-based-on-a-pattern

Resources