VBScript for A.D. Help

Status
Not open for further replies.

CntdwnToExtn

Fully Optimized
Messages
1,746
Location
Parents Basement...Still
i have this script to display what groups each "user" belongs to in a specific OU

Code:
On Error Resume Next

Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D

Set objOU = GetObject _ 
	("LDAP://cn=users,dc=MyDomain,dc=com")
  
ObjOU.Filter = Array("user")
 
For Each objUser in objOU
    WScript.Echo objUser.cn & " is a member of: " 
    WScript.Echo vbTab & "Primary Group ID: " & _
        objUser.Get("primaryGroupID")
  
    arrMemberOf = objUser.GetEx("memberOf")
  
    If Err.Number <>  E_ADS_PROPERTY_NOT_FOUND Then
        For Each Group in arrMemberOf
            WScript.Echo vbTab & Group
        Next
    Else
        WScript.Echo vbTab & "memberOf attribute is not set"
        Err.Clear
    End If
    Wscript.Echo 
Next

which successfully finds all the users in the "Users" OU

however, i want it to find users in a different OU

i specifiy
Code:
Set objOU = GetObject _
("LDAP://cn=Different OU,dc=MyDomain,dc=com")

however the results turn up blank when i know there are users.

am i missing something here?
not all that familiar with VBS.

thanks
 
Wrong forum?? I dont think this should be in the Windows area.
 
What you want to specify in this section depends on your AD structure

Code:
("LDAP://cn=users,dc=MyDomain,dc=com")

Looking at your AD tree, it works from the inner-most OU out in your AD structure, left to right in your LDAP query.
For example, you want to target SubSubOU1 in the following example located here.

Code:
MyDomain.com
    OU1
    OU2
    OU3
        SubOU1
        SubOU2
             SubSubOu1
   OU4

The code for this would be
Code:
("LDAP://cn=SubSubOU1,cn=SubOU2,cn=OU3,dc=MyDomain,dc=com")

Does that make sense a bit?
 
Status
Not open for further replies.
Back
Top Bottom