How to – Domain Name UPN Email Primary SMTP SIP Change

It is common when a business acquisition or merging occurs, to IT professionals, we would automate our task via scripting rather than going through each user’s properties and changing everything, the below simple scripts may help when you want to “bulk change” domain name, UPN, Email Attribute, Primary SMTP, SIP address in a Hybrid environment: On-premise Actotry Directory with Azure AD Connect.


  1. Customer having on-premise Active Directory server, Azure AD Connect is syncing all the needed users onto Office365 cloud
  2. Exchange Online and Microsoft Teams by Office365
  3. Currently, UPN, Email attribute, Primary SMTP, and SIP address (Proxyaddress attributes) are the same, it is simply Microsoft best of practice


======List out Users attributes as backup prior to the change=============

Get-ADUser -Filter * -SearchBase ‘OU=Standard,OU=Accounts,OU=TEST,DC=ICTFELLA,DC=COM’ -Properties * | Select-Object name, DisplayName, EmailAddress, UserPrincipalName, LastLogonDate, @{“name”=”proxyaddresses”;”expression”={$_.proxyaddresses}} | export-csv -path c:\temp\allusers2.csv

=========Change UPN name for each user within located OU======

$LocalUsers = Get-ADUser -LDAPFilter ‘(userPrincipalName=*)’ -SearchBase “OU=Standard,OU=Accounts,OU=TEST,DC=ICTFELLA,DC=COM” -Properties userPrincipalName

$LocalUsers | foreach {$newUpn = $_.UserPrincipalName.Replace(“”,””); $_ | Set-ADUser -UserPrincipalName $newUpn}

=====change “mail” attribute============

Get-ADUser -Filter * -Properties givenName, Surname, EmailAddress -SearchBase “OU=Standard,OU=Accounts,OU=TEST,DC=ICTFELLA,DC=COM” | foreach {Set-ADUser -identity $_ -EmailAddress “$($_.givenName).$($_.Surname)”}

=======Adding SMTP and SIP address=======

Get-ADUser -Filter ‘Name -like “*”‘ -SearchBase ‘OU=Standard,OU=Accounts,OU=TEST,DC=ICTFELLA,DC=COM’ -Properties proxyaddresses | % {Set-ADUser $_ -add @{proxyAddresses=”SMTP:”+ $_.GivenName + ‘.’ + $_.Surname +””}}

Get-ADUser -Filter ‘Name -like “*”‘ -SearchBase ‘OU=Standard,OU=Accounts,OU=TEST,DC=ICTFELLA,DC=COM’ -Properties proxyaddresses | % {Set-ADUser $_ -add @{proxyAddresses=”SIP:”+ $_.GivenName + ‘.’ + $_.Surname +””}}

Note or other Considerations

  1. Always backup everything prior to the production change
  2. Line up the change with Email Security products such as Mimecast or MailGuard
  3. Email Signatures, forwarding rules, antispoofing rule updating
  4. Public DNS, 3rd party application using SAML or other Federation services
  5. Exchange resource accounts, distribution list
  6. Enterprise Root CA service and Authentication

Useful Links

Leave a Comment

Your email address will not be published. Required fields are marked *