Avatar of vmich
vmich
Flag for United States of America asked on

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

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?
Exchange

Avatar of undefined
Last Comment
Qlemo

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Saif Shaikh

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
vmich

ASKER
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 Shaikh

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
vmich

ASKER
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.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Saif Shaikh

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

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

vmich

ASKER
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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Qlemo

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

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

ASKER
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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
vmich

ASKER
Qlemo,
Any answer for me using the new company name to apply the secondary smtp just to them?
Qlemo

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

vmich

ASKER
Ok Ill try it now
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
vmich

ASKER
Well I tried it but there must be a typo in there somewhere because it doesn't run.
Qlemo

"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.
vmich

ASKER
Sorry
Well I was just getting  A red cursor at the beginning of it once I copied and pasted it into PS
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
vmich

ASKER
I will try the first line without the pipe
Qlemo

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