Command to add secondary smtp address to all new users from aquired new company

vmich
vmich used Ask the Experts™
on
We are migrating users to our domain from another company that we acquired. Exchange 2016
I need the command to add a secondary smtp address to all of the users from the acquired company
So our domain is abcd.com and their domain is 1234.com
So how would I make their domain 1234.com, as a secondary smtp address for all of their users at once instead of having to do each user one at a time?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Server engineer
Commented:
Try this in powershell.
1. Open PS in elevated mode
2. Run command: add-psssnapin *2010*

3. Create a AddEmailAddress.csv CSV file with new email addresses.

This example imports data from C:\Users\Administrator\Desktop\AddEmailAddress.csv, which has the following format.

Copy
Mailbox,NewEmailAddress
Dan Jump,danj@northamerica.contoso.com
David Pelton,davidp@northamerica.contoso.com
Kim Akers,kima@northamerica.contoso.com
Janet Schorr,janets@northamerica.contoso.com
Jeffrey Zeng,jeffreyz@northamerica.contoso.com
Spencer Low,spencerl@northamerica.contoso.com
Toni Poe,tonip@northamerica.contoso.com


Import-CSV "C:\Users\Administrator\Desktop\AddEmailAddress.csv" | foreach {Set-Mailbox $_.Mailbox -EmailAddresses @{add=$_.NewEmailAddress}}

OR

Get-Mailbox -Database "XXX Users DB" | Set-Mailbox @{Add="$($_.Alias)@newdomain.com"}

Author

Commented:
Saif,So
Can I do this without having to create a csv file?
Like just running a command in powershell?
If so can you show me how me how the command would be?
I am not a powershell expert.
So as I said our main domain is = adcd.com
The company we bought their domain = 1234.com
So what would the command look like to make their domain 1234.com be secondary and our domain abcd.com be primary?
Saif ShaikhServer engineer

Commented:
Get-Mailbox -Database "XXX Users DB" | Set-Mailbox @{Add="$($_.Alias)@newdomain.com"}

The above command: Get-Mailbox -Database "XXX Users DB" (Will pull all users from the database XXX)

And PIPE command i.e. Set-Mailbox @{Add="$($_.Alias)@newdomain.com"}  ( Will set the new email addresses as secondary on all mailboxes)

@newdomain would be your new company name @1234.com
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
I just talked with my manager and company that we bought they are already have email accounts on our domain 1234.com
We will be cutting them over from their email tomorrow.
So basically I just need to add their old domain abdc.com to each of the users as a secondary domain on our domain.
I am not sure what dbs their on but I just need a basic command to add as I said the secondary (their old domain) to each of their new mailboxes on our domain.
Sorry for tying a lot just want to be sure I have it correct.
Saif ShaikhServer engineer

Commented:
If you want to do for all mailboxes and forget about DB's or don;t know the DB names then simple command:

Get-Mailbox | Set-Mailbox @{Add="$($_.Alias)@newdomain.com"}

Here get-mailbox (Will pull all mailboxes from all databases) and set new email address.
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
Please note that the above command will create aliases for all mailbox, because there is no filtering done. For test, I would use the common switch -WhatIf to simulate operations only.
Get-Mailbox | Set-Mailbox @{Add="$($_.Alias)@newdomain.com"} -WhatIf

Open in new window

Author

Commented:
Saif, Qlemo,
But my issue is we only want this for the users coming on from the company we merged with, not any changes to existing users in our domain.
So the users from the company we purchased (1234.com) now have email accounts on our domain (abcd.com) So where would I put into the command so that only the users from the company we purchased, who now are on our domain, can have their old domain (1234.com) as a secondary smtp address?

Get-Mailbox | Set-Mailbox @{Add="$($_.Alias)@newdomain.com"} -WhatIf
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
You need something to identify those users, e.g. an AD attribute like Company Name, which can get queried to create a filter.

Other than that, your only choice is to put together a manual list of AD or mailbox user names into a file or variable.

Both have to assume the email is the same in both domains with exception of the domain name. Or there is another simple rule to build the old email address.
For bulding a manual list you could run
get-mailbox example_account | fl *

Open in new window

look at what field can be used best to build the secondary address, and then build a simple list
get-mailbox | select -Expand TheAtttributeToUse | Out-File C:\Temp\listOfAccounts.txt

Open in new window

you can remove every account not  to receive a secondary email address.

Tell us your decision how to proceed, and then we can adapt the command.
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
Do you happen to have a list of the "old" email addresses? You could use that one instead of the one described above.

Author

Commented:
Yes we do have their company name.
So if the company name is SMITH, how would the command look that I would need to run

Author

Commented:
Qlemo,
Any answer for me using the new company name to apply the secondary smtp just to them?
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
I'm still not at a computer, so cannot test, but this should work:
Get-ADUser -Filter {Company -eq '1234'} -Property mail |
  Get-Mailbox |
  Set-Mailbox @{Add="$($_.mail -replace 'abcd', 1234')@1234.com"} -WhatIf

Open in new window

Author

Commented:
Ok Ill try it now

Author

Commented:
Well I tried it but there must be a typo in there somewhere because it doesn't run.
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
"doesn't run" means exactly what? Is it just not processing anything, or do you get an error? You can try the first line (without the pipe) to see if the filter condition works.

Author

Commented:
Sorry
Well I was just getting  A red cursor at the beginning of it once I copied and pasted it into PS

Author

Commented:
I will try the first line without the pipe
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
You certainly accepted the wrong comment, respective "closed" the question accidentally?!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial