Link to home
Create AccountLog in
Avatar of Garan T
Garan TFlag for United Kingdom of Great Britain and Northern Ireland

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  

Avatar of Clément SERAFIN
Clément SERAFIN
Flag of France image

$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}


}


This script may help you

ASKER CERTIFIED SOLUTION
Avatar of Clément SERAFIN
Clément SERAFIN
Flag of France image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer