query to active directory

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
Posts: 1
Joined: Sat Apr 05, 2008 3:11 am

query to active directory

Post by trixs »

I need to query active directory, if in organization unit GROUPS exist group with defined name.
Set objGroup = GetObject("LDAP://CN=" & GroupName & ",ou=groups,dc=domain,dc=com")

How to do it?
Thnx for help.

User avatar
Posts: 416
Joined: Thu Nov 16, 2006 9:02 pm

query to active directory

Post by donj »

I'm not sure I understand. You want to see if a specified group exists within the Groups OU?

The query you have should do just fine. If it doesn't return any object (e,g., IsObject(objGroup) = False), then the group doesn't exist.

Posts: 14552
Joined: Tue May 22, 2007 9:57 am

query to active directory

Post by jvierra »

trixs -
The structure you are describing looks like th efollowing from your description and LDAP:



|------- Groups

|------- OU1
|------- OU2

To get the "OU" OU within the "Groups" OU you need to do the following query.

Code: Select all

aOUName = "OU1"
Set objGroup = GetObject( "LDAP://ou=" & sOUName & ",ou=Groups,dc=domain,dc=com")

Assuming that this will return a collection of "group" type objects you can then enumerate the collection.

You can also get a group directly knowing it's name. Assuming group name is XXX and OU is OU1

Set objGroup = GetObject( "LDAP://cn=XXX,ou=OU1,ou=Groups,dc=domain,dc=com")

This will return the group with "CN" (Canonical Name) of "XXX" that resides in the "OU1" OU within the "Groups" OU.

The ksy is to "point at a container". The container can be an OU, a folder or a container. Then preface the container path with the CN of the item in the container. (CN=itemname). There are other methods but this is most direct and usual.

The choice of names here makes this very hard to explain.
jvierra2008-04-05 11:49:44