SOLVED

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

Copper Contributor

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 ADD the existing primary email address as an alias, without deleting the existing aliases.

 

We would like to use powershell, importing from a .csv file, but cannot determine the powershell syntax needed to handle both the primary replacement, and the addition of the current primary to the proxyaddresses field, without wiping out the existing proxyaddresses list.

 

We were also considering running two separate powershells to handle this.  The first one would replace the existing primary with the new email address, but we read that when you do that, it automatically adds the existing primary as an alias, which is what we want, but deletes the existing aliases, which we definitely do not want.

 

Any help with a single script that would replace the primary, and ADD the existing primary as an alias would be appreciated.  If a single script can't do this, is there a way to replace the existing primary with a new email address that does not wipe out the existing proxyaddresses list during the process?  We would then run a second powershell to add an alias to the list.

 

Thank you - April

2 Replies
best response confirmed by sunflower sunflower (Copper Contributor)
Solution

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

What a great, thorough response.  Thank you for your assistance.

 

April

1 best response

Accepted Solutions
best response confirmed by sunflower sunflower (Copper Contributor)
Solution

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

View solution in original post