Create exchange 2010 distribution group based on the "office" attribute in Active Directory


I would like to add all users in Active Directory that have the office attribute set to "Turtle" to a distribution group called "Turtle All Staff".

Would this work?
get-recipient -filter {Office-eq "Cayman"} | Add-DistributionGroupMember -Identity "Turtle All Staff"
Who is Participating?
Jamie McKillopIT ManagerCommented:

Try this:

get-recipient -filter {(Office-eq "Cayman")} | foreach-object {Add-DistributionGroupMember -Identity "Turtle All Staff" -member $_.alias}

Adam BrownSr Solutions ArchitectCommented:
Alternatively, you can create a dynamic distribution group.

new-dynamicdistributiongroup -name "Turtle All Staff" -alias "TurtleAllStaff" -organizationalunit "" -recipientfilter {(objectclass -eq "user") -and (office -eq "Cayman")} -recipientcontainer ""

Would create a dynamic DG that would include all current users and all future users that have an office of Cayman.
Adam BrownSr Solutions ArchitectCommented:
correction, that should be objectclass -eq "usermailbox" not objectclass -eq "user"
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.

All Courses

From novice to tech pro — start learning today.