Office 365 will look to the email field to set the user’s primary email address in the Office 365 portal. Each user will need their Email field or their “mail” attribute field populated to ensure the proper primary SMTP address. Without this, you will find that accounts will be created, but the primary SMTP address in the Office 365 portal will show as [highlight]username@domain.onmicrosoft.com[/highlight]. Since Office 365 DirSync is enabled, you will not be able to change it in the Office 365 portal.

The easiest way to do this is with a PowerShell script. This script will copy their UPN to their Email field. If you have already changed the UPN for all users, this will work perfectly.

  1. Open Notepad on the AD Server
  2. Paste the following into a new text document and edit based on domain and AD OU structure:
  3. Get-ADUser -LDAPFilter '(userPrincipalName=*)' -SearchBase "OU=EditedEmailUsers,OU=Users,OU=papcsh,DC=papcsh,DC=local" -Properties mail, userPrincipalName |  
        ForEach-Object {Set-ADObject -Identity $_.DistinguishedName -Replace @{mail=$($_.userPrincipalName)}}
    
  4. Do a Save As with the .ps1 extension and click OK
    You can right click and edit the script and run a debug in PowerShell ISE to ensure that the formatting is correct.

  5. Run the script as Administrator
  6. Verify in AD that is has changed the Email field for users in the relevant OU

Done!

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu