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.
This topic is 15 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
trixs
Posts: 1
Last visit: Sat Apr 05, 2008 3:24 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
donj
Posts: 416
Last visit: Thu May 29, 2008 5:08 am

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

query to active directory

Post by jvierra »

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

LDAP://CN="ou=ou1,ou=Groups,dc=domain,dc=com"

LDAP://CN="ou=ou2,ou=Groups,dc=domain,dc=com"

LDAP://CN="ou=ou1,ou=Groups,dc=domain,dc=com"
domain.com
|
|------- Groups

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


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
This topic is 15 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked