Powershell script to bulk add email to distribution lists and set as primary for 365 online

Here is the deal.

We have company that would like to add the new domain name and change the primary email address for all users to a new domain they have purchased. It has been added to  365 online. They would also like to do the same for distribution lists.

 I have found a script that will do so for mailboxes at the following site :
http://exchangeserverpro.com/powershell-script-create-mailbox-size-report-exchange-server-2010/

This works well in our test env.

Contoso.com also has many distribution lists. Is there another script that will allow me to do the same for distribution lists in bulk? I was only able to find scripts to do so one at a time. See script syntax below.


Set-DistributionGroup "<Distribution Group Name>" -EmailAddresses SMTP:<Primary Email>,<Alias Email>
shamilt1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vasil Michev (MVP)Commented:
Just use the -WindowsEmailAddress parameter, it will add the new alias as primary SMTP while preserving the old one as secondary alias:

Set-DistributionGroup DGname -WindowsEmailAddress new@domain.com

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Will SzymkowskiSenior Solution ArchitectCommented:
There is no need to do this via a script. If this is a new domain they have purchased and they want to use tihs as their primary SMTP Address then all you need to do is the following...

- create a new accepted domain for this domain i.e. newname.com
- update the default email address policy with the new domain name (referencing the accepted domain)
- apply the policy to the mailboxes and distribution groups

This would be a preferred method rather than a script because if you use a script when you create new mailboxes they will get the old email address from the default email address policy.

Will.
shamilt1Author Commented:
This helps, saves the step of having to add alias email address in the script, thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Office 365

From novice to tech pro — start learning today.