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.

Environment

  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

Solution

======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(“testdomain.com”,”ICTFELLA.com”); $_ | 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)@ictfella.com”}

=======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 +”@ictfella.com”}}

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 +”@ictfella.com”}}

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

https://docs.microsoft.com/en-us/powershell/module/activedirectory/set-aduser?view=windowsserver2019-ps

Leave a Comment

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