Re: Need Help. Beginner in Scripting



Daniel wrote:

I am trying to get members list from all the groups in same OU.

I found this sample code in Script Repository but I would have to enter
each
group names for about 200 groups in 5 different OUs.

Is there an easier way I can automate the process?

thank you so much for your help

------------------------------------------------------------------------------
On Error Resume Next

Set objGroup = GetObject _
("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com";)

objGroup.GetInfo

arrMemberOf = objGroup.GetEx("member")

WScript.Echo "Members:"
For Each strMember in arrMemberOf
WScript.echo strMember
Next

------------------------------------------------------------------------------

Hi,

Unless all the objects you seek (groups in this case) are in the same
OU/Container, the most efficient way to search Active Directory is with ADO.
I have a sample VBScript program to document all groups in the domain linked
here:

http://www.rlmueller.net/Document%20Domain%20Groups.htm

If all of your OU's are in the same hierarchy of AD, you can modify the base
of the ADO search in this script. Or, you could modify the program to search
each of the 5 OU's separately. You would modify the query defined by this
statement:

strQuery = "<LDAP://"; & strDNSDomain _
& ">;(objectClass=group);distinguishedName;subtree"

For example, if one OU is "ou=Sales", you could use:

strQuery = "<LDAP://ou=Sales,"; & strDNSDomain _
& ">;(objectClass=group);distinguishedName;subtree"

Another approach would be to modify the snippet you posted to enumerate
groups in a specified OU. For example:

' Bind to specified OU/Container.
Set objOU = GetObject("LDAP://ou=Sales,dc=MyDomain,dc=com";)

' Filter on group objects.
objOU.Filter = Array("group")

' Enumerate all groups.
For Each objGroup In objOU
' Enumerate direct members of each group.
For Each objMember In objGroup.Members
Wscript.Echo objMember.sAMAccountName
Next
Next

In this example, I used the "Members" method of the group object to
enumerate members, rather than the "member" attribute used in your example.
The "member" attribute is a multivalued collection of member Distinguished
Names. The "Members" method returns a collection of member objects. Because
they are objects, you can refer to any attributes of the objects. I choose
to output the sAMAccountName attribute of each member, which is the NT Name
(also called the "pre-Windows 2000 logon name"). You could instead output
the distinguishedName attribute (in which case the output would be the same
as if you enumerated the member attribute), or you could output any other
attribute. Note that members could be users, computers, or groups.

You could run the above example once for each of the 5 OU's/Containers. Or,
you could modify it to automatically document all 5 OU's, using some kind of
loop. In brief:

arrstrOUs = Array("ou=Sales,dc=MyDomain,dc=com", _
& "ou=East,dc=MyDomain,dc=com", _
& "ou=West,dc=MyDomain,dc=com", _
& "ou=Engineering,dc=MyDomain,dc=com", _
& "ou=Accounting,dc=MyDomain,dc=com")

For Each strOU in arrstrOUs
Set objOU = GetObject("LDAP://"; & strOU)
' Code as above to enumerate groups in the OU.

Next

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net


.



Relevant Pages

  • Re: New Scripter - Listing members of Groups in AD
    ... The Script am using is: ... You need to bind to the member object to retrieve ... Dim objGroup, objMember ... you can enumerate all the groups in the OU. ...
    (microsoft.public.windows.server.scripting)
  • Re: Query users from specific groups
    ... specific groups, starting with "ras". ... You can use ADO in a script. ... It will return the NetBIOS name of the group and the member ... enumerate the memberOf attribute, which is similar to the member attribute. ...
    (microsoft.public.windows.server.scripting)
  • Re: Can i browse active directory without being Administrator?
    ... How can I browse Active Directory if i am just a regular user? ... enumerate the direct members of a group could be: ... A VBScript program to enumerate the groups a user is a direct member of: ...
    (microsoft.public.windows.server.active_directory)
  • Re: Enumerate group members and nested group
    ... access the group properties so that I can then enumerate its members. ... The Class method of the member object indicates the class of the member, ... enumerate direct members and indicate the class of each member. ... avoid an infinite loop if you have any circular nested group situations (for ...
    (microsoft.public.scripting.vbscript)
  • Re: Enumerate group members and nested group
    ... After determining that the member is a group then I would need to ... access the group properties so that I can then enumerate its members. ... enumerate direct members and indicate the class of each member. ... avoid an infinite loop if you have any circular nested group situations (for ...
    (microsoft.public.scripting.vbscript)