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.
- Open Notepad on the AD Server
- Paste the following into a new text document and edit based on domain and AD OU structure:
- 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. - Run the script as Administrator
- Verify in AD that is has changed the Email field for users in the relevant OU
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)}}
Done!