List all members of all groups

Discussion in 'Scripting' started by fatimas, Dec 2, 2003.

  1. fatimas

    fatimas Guest


    How can do to get a list of all members of all groups in a

    fatimas, Dec 2, 2003
    1. Advertisements

  2. fatimas

    Robert Cohen Guest

    This script works for me. You would have to change the GC address. I
    believe this is a Richard Mueller script so you can go to his website for
    hints if it doesn't work.

    Set objConnection = CreateObject("ADODB.Connection")
    objConnection.Open "Provider=ADsDSOObject;"

    Set objCommand = CreateObject("ADODB.Command")
    objCommand.ActiveConnection = objConnection

    objCommand.CommandText = _
    "<GC://dc=baltimorebehavioralhealth,dc=org>;(objectCategory=Group);" & _

    Set objRecordSet = objCommand.Execute

    While Not objRecordSet.EOF
    Wscript.Echo objRecordSet.Fields("Name")
    Wscript.Echo "[" & _
    objRecordSet.Fields("distinguishedName") & "]"

    Wscript.Echo "Group Member(s):"
    arrMembers = objRecordSet.Fields("member")

    If IsArray(objRecordSet.Fields("member")) Then
    For Each strMember in arrMembers
    Wscript.Echo vbTab & strMember
    Wscript.Echo vbTab & "None"
    End If
    Wscript.Echo VbCrLf

    Robert Cohen, Dec 2, 2003
    1. Advertisements

  3. Hi,

    Note that the "member" attribute of the group object does not include
    members that have the group designated as their "primary" group. This is a
    limitation of the LDAP provider. For example, if all members of the group
    "Domain Users" have that group designated as their primary group, the
    program Robert posted will show the group to be empty. However, unless you
    have changed the default primary group for users, you should be able to
    assume that every user is a member of "Domain Users".

    Microsoft MVP Scripting and ADSI
    HilltopLab web site -
    Richard Mueller [MVP], Dec 2, 2003
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.