Add Email Address to Existing AD Users for Office 365 via PowerShell

Use Case: Needed a quick and dirty way to update on premise Active Directory user objects in preparation to sync with a new Office 365 tenant for a client who was migrating to Exchange Online from a POP3 service … with no on premise Exchange.

The following script allows us to update the email field, add a default proxy address, and update the UPN suffix for all users in an existing Active Directory environment.

We will need to add our domain name to the script by replacing domainname.com.

NOTE: This script must be run from an elevated PowerShell console and assumes that the UPN suffix being added exists in the domain and will match the email address being assigned.

 

Import-Module ActiveDirectory
$USERS = Get-ADUser -Filter *
foreach ($USER in $USERS)
{
   $EMAIL = $USERS.SamAccountName + 'domainname.com'
   Set-ADUser $USERS -UserPrincipalName $EMAIL -EmailAddress $EMAIL -Add @{proxyAddresses = ("SMTP:" + $EMAIL)}
}

 

To see proxyAddresses for a user…

  1. Open Active Directory Users and Computers
  2. Click View (from the toolbar) and enable Advanced Features
  3. Open the Properties of a user and select the Attribute Editor tab
  4. Scroll down to locate ‘proxyAddresses’ and click Edit

AD proxyAddresses

 

If you have a recommendation to make the script more efficient or want to provide other suggestions on what works for you, please comment.

NOTE: There is a difference between proxy addresses being set as the default reply email address vs. an alternate email address. The default reply address is set by adding ‘SMTP:’ (in all caps) in front of the proxy address. This email address will be what recipients see when an email is sent from you. Alternately, ‘smtp:’ (in all lowercase) is simply an additional email address a mailbox can receive email with. This script does not take into account that there may already be a default reply address set. Also, the ‘EmailAddress’ attribute is not tied to the ‘proxyAddresses’ attribute and setting one does not set the other.

Have fun!

 

Reference(s):

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s