Pages

iDrive

IDrive Remote Backup

Friday, 23 March 2018

Swap the primay SMTP address from old domain to new one in Office365 with ADD Connect

Hello everyone,
I worked with this method several times and it is very useful and efficient when your customer in Office365 and you have AAD Connect in place and they want to change their primary domain with a new one say, the old one is cats.com to dogs.com and you need to deal with a lot of number of mailboxes, the steps are:
  1. In the Office365 and from the Active Users screen export the users to .csv
  2. Clean the sheet and leave the UPN and the Primary SMTP Address columns.
  3. Clean the UPN column by removing everything after the @. 
  4. Add the new email addresses in another column to the sheet.
  5. Change the heading in the sheet for the UPN to username for old smtp to OldEmail and for the new smtp NewEmail.
  6. Save the file as users.csv and copy it to the DC.
  7. Stop the AAD Connect from services till you finish all the process.
  8. Remove the old primary SMTP email address run the following:
    import-csv C:\temp\users.csv | foreach ({Set-ADUser -identity $_.Username -Remove @{proxyAddresses = "SMTP:"+($_.OldEmail)}})
  9. To add the new primary SMTP
    import-csv C:\temp\users.csv | foreach ({Set-ADUser -identity $_.Username -Add @{proxyAddresses = "SMTP:"+($_.NewEmail)}})
  10. To add the old primary as a secondary SMTP
    import-csv C:\temp\usesr.csv | foreach ({Set-ADUser -identity $_.Username -Add @{proxyAddresses = "smtp:"+($_.OldEmail)}})
  11. To check the changes:
    import-csv C:\temp\users.csv | foreach ({Get-ADUser -identity $_.Username -Properties *})| fl DisplayName,proxyaddresses
  12. After everything changed as you wish, start the AAD Connect services and watch the magic!