Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Query Based Distribution Group based on OU membership

Posted on 2005-02-25
Medium Priority
Last Modified: 2008-03-06
I am trying to create a query based distribution group that simply contains all of the users contained within a particular OU.  Is anybody aware of the Ldap query that will produce this?
Question by:andrewgallop
  • 2
LVL 35

Expert Comment

by:Nirmal Sharma
ID: 13402171
You can use LDIFDE utility to do so.
LVL 35

Accepted Solution

Nirmal Sharma earned 1000 total points
ID: 13402176

Assisted Solution

ScrptMasta earned 1000 total points
ID: 13403424
So you want to create a group based on members in a particular OU ?

What this script will do is first greate a Global Distribution group called "scientists" in the R&D ou in the NA.fabrikam.com domain. We'll give it 5 seconds to do its thing and then we are going to give it a couple of OU's to go through. You can add as many OU'd to the arrOU array as you wish it will go through each one of them and as it gets the members of the OU it will add them to the scientists group. Obviously you need to change the script to fit your needs.

On Error Resume Next


Set objOU = GetObject("LDAP://ou=R&D,dc=NA,dc=fabrikam,dc=com")
Set objGroup = objOU.Create("Group", "cn=Scientists")

objGroup.Put "sAMAccountName", "scientists"
objGroup.Put "groupType", ADS_GROUP_TYPE_GLOBAL_GROUP

Wscript.Sleep 5000

Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

arrOU = Array("CN=Builtin,","CN=Users,")

For each mOU in arrOU
    Set objOu = GetObject("LDAP://" & mOU & strDNSDomain)

    For each obj in objOu
       Set objGroup = GetObject ("LDAP://cn=Scientist,OU=R&D,dc=NA,dc=fabrikam,dc=com")
       objGroup.PutEx ADS_PROPERTY_APPEND,"member", Array(obj.name & mOU & strDNSDomain)

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question