Exchange 2010 Add Email Address to Distribution Groups

I have about 500 Distribution Groups and 700 Mail Contacts to whom I need to add a secondary email address to (the same email domain ie.
is there a script someone can post which can point me in the right direction?
Who is Participating?

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

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.

Will SzymkowskiSenior Solution ArchitectCommented:
This is pretty straightforward. You can use the following script below...

In your CSV file make sure that you have 2 column headings one for DistributionGroup and one for Contact. Example below...

DistributionGroup    Contact
HRDis1                        Contact1
AccDis2                       Contact2

Then run the below script. Make sure that you change the filename for your CSV path.

$Import = Import-Csv "c:\filename.csv"
ForEach ($DG in $Import)


            Add-DistributionGroupMember -Identity $DG.DistributionGroup -Member $DG.Contact


Open in new window

AmitIT ArchitectCommented:
You can also create separate email address policy.
Jarred PowerNetwork AdministratorCommented:
There is a couple ways you can do this - ( I had to do this for few distributions group a little while back.)

I like to tests things before I do the full blast  - so the first way  we output to a .csv file and make the change in excel  (add the address we want), then test with only a the first 5 or so groups and make sure it's what we are looking for then more on to the full block.

Get-DistributionGroup | Select-Object SamAccountName,PrimarySmtpAddress | Format-Table | > c:\distro.csv

Open in new window

This will list the primary addresses for each group.

Then change the SamAccountName column to just "name" and add the alias column with the new address - excel can do this a number of different ways
Name           PrimarySmtpAddress                                        alias

Then import the updated .cvs file back in. * adds email address to group -
Import-CSV c:\distro.csv | ForEach {Set-DistributionGroup $_.Name -PrimarySmtpAddress @{add=$_.PrimarySmtpAddress,$_.alias}}

Open in new window

You can do a simlar thing with the contacts ie.  Get-Contact | format-table > c:\contacts.cvs ........
nutekconsultantAuthor Commented:
Hi Jpower5000 - when I run the above command I get the following error.   I have edited the csv file to include Colomns as you mentioned, then copied/pasted the command

[PS] C:\Windows\system32>Import-CSV c:\distrotest.csv | ForEach {Set-DistributionGroup $_.Name -PrimarySmtpAddress @{add

Cannot process argument transformation on parameter 'PrimarySmtpAddress'. Cannot convert the "System.Collections.Hashta
ble" value of type "System.Collections.Hashtable" to type "Microsoft.Exchange.Data.SmtpAddress".
    + CategoryInfo          : InvalidData: (:) [Set-DistributionGroup], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-DistributionGroup
Jarred PowerNetwork AdministratorCommented:
You have to have both the primary and alias addresses in the input field (not just the alias)

{add=$_.alias}}  will not work has to be {add=$_.PrimarySmtpAddress,$_.alias}  

I know you are not changing the primary address but it needs both when adding the secondary for some reason.  

Make sure you have both variables in in your .csv file.

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

From novice to tech pro — start learning today.