Skip to main content

Stamping multiple AD users with Primary SMTP Addresses for Office 365 Hybrid

By April 29, 2015September 9th, 2020Blog, Microsoft, Office 365, Office 365

If you have a hybrid exchange office 365 environment and you no longer have mailboxes on-premises, you may find that it is a pain to create new users, create their new mailbox, then migrate it to the cloud.

The best way to accomplish this is to create your users, assign them a proxy address and then do your dirsync.

If you have to create a lot of users at once, you may not want to touch each user in ADSI edit to assign their primary SMTP address.  If this applies to you, you can use this powershell to assign a primary SMTP Proxy address to your new AD users in bulk before synchronizing them with the Office 365 tenant.  It is important you create your users and run this script BEFORE they sync with the tenant, otherwise they will get stamped with the default Microsoft tenant ID SMTP address which is very difficult to remove once it is there

Import-Module ActiveDirectory

$newproxy = “@domain.com”

$userou = ‘ou=users,dc=pei,dc=com’

$users = Get-ADUser -Filter * -SearchBase $userou -Properties SamAccountName, ProxyAddresses

Foreach ($user in $users) {

    Set-ADUser -Identity $user.samaccountname -Add @{Proxyaddresses=”SMTP:”+$user.samaccountname+””+$newproxy}

    }

Once you have run the script, you can synchronize and your new users will be in the cloud and ready to be licensed and email enabled.

Josef Hanning, PEI

Leave a Reply