Adding new SMTP mail address and set primary SMTP and Change User ID

Zwe Thu Ko 126 Reputation points
2021-12-29T11:03:08.38+00:00

Dear,

One of our clients wants to change the domain test@jaswant .net to test@jaswant .com.

The old domain will be receiving mail (abc.net) till one month.

There are 250 mailboxes we need to change their primary email domain to a new domain.

Here is I test PowerShell for single user.

Adding new SMTP mail address and set Primary

Set-Mailbox "Test One" -EmailAddresses "SMTP:test@jaswant .com","test@jaswant .net"

Change User ID

Set-MsolUserPrincipalName -UserPrincipalName test@jaswant .net -NewUserPrincipalName test@jaswant .com

Please help PowerShell using CSV to add new SMTP address and set the primary email address and change User ID for multiple account (250 Mailboxes).

Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,624 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Andy David - MVP 150.3K Reputation points MVP
    2021-12-29T13:54:28.72+00:00

    You can do this all with set-mailbox and the Exchange Powershell:

    Create a csv with two columns and populate the values for :

    UserPrincipalName
    (Current UPN)

    PrimarySMTPAddress
    (New UPN and Primary SMTP)

    then with Exchange online powershell:

    $mailboxes = import-csv Mailboxes.csv
    $mailboxes |% {Get-mailbox -UserPrincipalName  $._UserPrincipalName| Set-mailbox -UserPrincipalName $._PrimarySMTPAddress -PrimarySMTPAddress $._PrimarySMTPAddress}
    

    Test with just a few first!!!!!

    Then if it looks good, run against the entire list


  2. Zwe Thu Ko 126 Reputation points
    2021-12-30T05:30:55.57+00:00

    Thanks AndyDavid, I'm testing on it.


  3. Shannon Dias 1 Reputation point
    2022-12-07T14:59:35.713+00:00

    Hi Andy,

    I have already added the alias with the new domain and want to switch the alias to primary and primary to alias, is there any script for that?

    Thanks

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.