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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Recently, I had the need to build a standalone system to run a point-of-sale system. I’m running this on a low-voltage Atom processor, so I wanted a light-weight operating system, but still needed Windows. I chose to use Microsoft Windows Server 200…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

770 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