Share via

Powershell command to change primary SMTP (reply address) for all users in Student OU

Anonymous
2019-06-14T11:09:12+00:00

Hello MS Community,

When students from my organisation send out emails internally/externally, the recipient will see their email address as:

******@company.onmicrosoft.com

When it should be:

******@student.company.ac.uk

Since we have a hybrid setup Office 365 (exchange online) is being synced with AD on-premise, meaning that you cannot change the objects primary SMTP online (only through active directory attribute editor). So all users in the "Student" OU need their SMTP swapped.

Is there a powershell script that I can use so that I can swap the primary SMTP from ******@company.onmicrosoft.comto ******@student.company.ac.uk for all users in the "Student" OU? (One thing to note is that we have two domain controllers).

Many thanks for your help!

IT Tech [Mo]

Microsoft 365 and Office | Subscription, account, billing | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2019-06-14T14:20:47+00:00

    Hello IT Tech [Mo],

    If you are using Exchange Hybrid environment, and user mailboxes are moved from Exchange on-prem to Online, based on my knowledge, it is suggested to use EMS to change user SMTP address: 

    Set-RemoteMailbox –Identity <user identity> -EmailAddress  SMTP*:<Primary Email Address>* ,<Alias Email Address 1>,<Alias Email Address 2>

    If you want to edit AD object properties in AD local via PowerShell script, you may need to change user EmailAddress and Proxy addresses properties :

    As far as I know, Get-ADUser command can filter user based on Active Directory path

    $path = "OU=TestOU,DC=contoso,DC=com"

    $users = Get-ADUser -SearchBase $path –Filter *

    And then update user addresses via Set-ADUser.

    Besides, since above commands for editing AD object properties may not satisfy your business needs, and we have limited capabilities regarding strictly coding PowerShell script, you are suggested to contact scripting forum to seek expert assistance: https://social.technet.microsoft.com/forums/en-us/home?category=scripting&filter=alltypes&sort=lastpostdesc

    Best Regards,

    Anna

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments