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

Hi,

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"
Treadstone21Asked:
Who is Participating?
 
Jamie McKillopIT ManagerCommented:
Hello,

Try this:

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

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

new-dynamicdistributiongroup -name "Turtle All Staff" -alias "TurtleAllStaff" -organizationalunit "domain.com/OUToStoreGroupIn" -recipientfilter {(objectclass -eq "user") -and (office -eq "Cayman")} -recipientcontainer "Domain.com"

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