List a user memberof including nested groups.

Discussion in 'Scripting' started by Kim Jensen, Aug 20, 2005.

  1. Kim Jensen

    Kim Jensen Guest

    Got this so far but is limited to one row of nested group.:

    Dim objSysInfo,objUser,objGroup1,objGroup2
    Dim strUserPath,arrMembersOf,strGroupPath1,strGroupPath2,GroupList
    Set objSysInfo = CreateObject("ADSystemInfo")

    strUserPath = "LDAP://" & objSysInfo.UserName
    Set objUser = GetObject(strUserPath)

    arrMembersOf = objUser.GetEx("memberOf")
    For Each strMemberOf in arrMembersOf
    strGroupPath1 = "LDAP://" & strMemberOf
    Set objGroup1 = GetObject(strGroupPath1)
    GroupList = GroupList & & ", "

    arrMembersOf1 = objGroup1.GetEx("memberOf")
    For Each strMemberOf1 in arrMembersOf1
    strGroupPath2 = "LDAP://" & strMemberOf1
    Set objGroup2 = GetObject(strGroupPath2)
    GroupList = GroupList & & ", "
    Msgbox "User: " & & vbnewline & _
    "Member Of: " & GroupList

    I want to extend is script to get them all and don’t kill the machine
    with loops. IE:
    John is member of Group1 which is member of Group2 which is member of
    Group3 which is member of Group4 and so on
    I don't need to know which group is member of which.
    So end result could look like this:
    User: John
    Member Of: Group1, Group2, Group3, Group4

    How could I accomplish this?
    Kim Jensen, Aug 20, 2005
    1. Advertisements

  2. If using a bat file and 3rd party utility is OK, see tip 9610 » How can I return the NetBIOS names of the local and domain groups that the logged on user is a member of?
    in the 'Tips & Tricks' at
    Jerold Schulman, Aug 21, 2005
    1. Advertisements

  3. Kim Jensen

    Kim Jensen Guest

    I was hoping it could be solved in VB and still trying to find which
    ..methods there is to a Getobject(Winnt://) Group object, other than .members
    But thanks for your reply, it might come handy, if I don’t find what I’m
    looking for
    Kim Jensen, Aug 23, 2005
    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.