asked on
Bulk change primary SMTP email address
How to bulk change the primary email address suffix of users in Exchange online/o365.
There was a period when we couldn't use our default domain as the default - something to do with federation or MFA/SSO. During this period ALL new users were created with the @companytenant.onmicrosoft.com suffix as their Primary SMTP email address.
We've got our default/proper domain now back and new users are getting the correct @ suffix but i notice that we have 100+ users with the @*.onmicrosoft.com suffix.
Is there a powershell script I can run that says something like:
Get All mailbox users - if suffix = @domain.onmicrosoft.com then change it to @properdomain.com
So at present we have bob@domain.onmicrsoft.com and we want to end up with bob@properdomain.com
Save me having to go into AD attributes and changing the Proxy SMTP address. and Synching.
p.s we're hybrid exchange online
This script may help you
$listuser = get-aduser -Filter * -Properties SamAccountName,proxyAddresses,mail
$DomainController = "your-dc"
$Newdomain = "properdomain.com"
foreach ($user in $listuser) {
$oldaddress = $user.mail -split "@"
$secondarysmtp = $user.mail
$Newaddress = $oldaddress[0] + "@" + $Newdomain
$UserEmails = @("SMTP:$Newaddress","smtp:$secondarysmtp")
$UserEmails
$SamAccountName = $user.SamAccountName
Set-ADUser -Identity $SamAccountName -Server $DomainController -Replace @{proxyAddresses=$UserEmails}
}