Link to home
Start Free TrialLog in
Avatar of vmich
vmichFlag 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?
ASKER CERTIFIED SOLUTION
Avatar of Saif Shaikh
Saif Shaikh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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?
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
Avatar of 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.
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.
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

Avatar of 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
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.
Do you happen to have a list of the "old" email addresses? You could use that one instead of the one described above.
Avatar of 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
Avatar of vmich

ASKER

Qlemo,
Any answer for me using the new company name to apply the secondary smtp just to them?
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

Avatar of vmich

ASKER

Ok Ill try it now
Avatar of vmich

ASKER

Well I tried it but there must be a typo in there somewhere because it doesn't run.
"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.
Avatar of vmich

ASKER

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

ASKER

I will try the first line without the pipe
You certainly accepted the wrong comment, respective "closed" the question accidentally?!