Exchange Add multiple users to Distr group based on AD group membership

How can I add members to an distr group in Exchange based on membership of an AD group.

Ex.
$members = (get-group Consultants).members
Add-distributiongroupmember -identity "Consultants" -members $members

This one fails. I would like this AD group Consultants to be queried each time to verify members and from there add them to the given mail distr group.
LVL 1
Mr WooberAsked:
Who is Participating?
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.

Marwan OsmanCommented:
Get-ADGroupMember "test11" | select samaccountname | export-csv "C:\users.csv" -NoTypeInformation
Import-CSV "C:\users.csv" | % {  
Add-ADGroupMember -Identity "test12" -Members $_.samaccountname
}

the above example will add the members of the group test11 to the group test12, run it from active directory powershell after importing the AD module by running import-module activedirectory

I verified it and it works successfully. then if you want to query the script automaticaly, you must add it to task scheduler.
0

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
Mr WooberAuthor Commented:
Hi,

It seems fine, If handling only Active Directory groups :)

I want (AD group) members to be added to (Exchange mail distribution list group). I am not able to add to mail distribution list based on samaccountname.

The logic will be that if a user is member of a AD group(consultants) he should be added to Mail Distribution list (consultants)
0
jontyulikeCommented:
Try this though littile effort but it works.

Create a Universal Security Group and add all the members to this Security Group.
Now add the Security group in Distribution group.

Hope this helps.
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Marwan OsmanCommented:
it must works since the exchange distribution group is integrated in active directory, did you try it?
0
Marwan OsmanCommented:
I just tried it and it is able to add the users to a distribution list group
0
Mr WooberAuthor Commented:
Marwan Osman, it worked.

I think you might have an "solution" for this one to :)

I would like the members to always be exact the same. I achieve what i asked for on how to add members, but how can I maintain that these members are always the same ?
0
Marwan OsmanCommented:
for sure it is the same unless an admin add a user to the Distribution group directly so this one will not be synchronized to the AD group, but surely every user added to the AD group will be synchronized to the Distribution group, if you want create a second script which export the users in the distribution group and add them to the AD, and run the 2 scripts on daily basis through the task scheduler :)
0
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
Exchange

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.