Results 1 to 5 of 5

Thread: VB script - List all user groups Help

  1. #1
    Join Date
    Nov 2008
    Posts
    21

    VB script - List all user groups Help

    VBS - List all user groups

    Hello forum

    I have plans to replace our login script (currently written in Kix) with a VBS script.This script (the new) is about to be completed. But in my tests, I realized that the code that I use to list the groups, lists only groups in the "member" of the properties of the user.

    The code is as follows:

    Code:
    Select All 
    Set ADSysInfo = CreateObject("ADSystemInfo") 
    Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName) 
    strGroupsUser = LCase(Join(CurrentUser.MemberOf)) 
    wscript.echo strGroupsUser
    Using the nesting groups (AGG-DL-P), I link access to certain shares to groups that do not appear on this tab, but the user is a member (through the interlocking groups) . Under Server 2003, the utility DsGet (with the proper parameters) can make this work.

    Beginner in this language, I would like to know if there is a piece of code VBS, to be able to retrieve the list of all groups which the user is a member.
    Thank you in advance for your help.

    Note: If there is another way to do what I want to do, I am open to any proposal

  2. #2
    Join Date
    May 2008
    Posts
    115

    Re: VB script - List all user groups Help

    Knowing that as a group, you can also access the memberOf property, it will have set up a recursive code.

    This could give something like this:

    Code:
    Select All 
    Set ADSysInfo = CreateObject("ADSystemInfo") 
    Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName) 
    strGroupsUser = LCase(Join(CurrentUser.MemberOf)) 
    For each grp in CurrentUser.MemberOf 
    seekGrp(grp) 
    Next 
    
    wscript.echo strGroupsUser 
    
    Sub seekGrp(groups) 
    Set objG = GetObject("LDAP:\\cn=" & groups & ",DC=...") 
    For Each grp in objG.MemberOf 
    strGroupsUser = strGroupsUser & grp 
    seekGrp(grp) 
    Next 
    End Sub

    A test, I wrote without accepting the execution. But I think the idea is there.

  3. #3
    Join Date
    Nov 2008
    Posts
    21

    Re: VB script - List all user groups Help

    Thanks For your Quick Reply
    I am studying your code.

    To begin with, I do not know if it's a mistake, but I replaced this

    Code:
     
    Select All 
    Sub seekGrp(groups) 
    Set objG = GetObject("LDAP:\\cn=" & groups & ",DC=...")
    by

    Code:
    Select All 
    Sub seekGrp(groupe) 
    Set objG = GetObject("LDAP://"& groups)
    as group returns a value of this type = CN = name of the group, OR = xxx, xxx OR = DC = foo, DC = lan

    Once this change of fact, when I come to the second loop, I get an error:
    Error: This object is not a collection
    Code: 800A01C3
    And here I do not know how to solve this problem.

  4. #4
    Join Date
    May 2008
    Posts
    115

    Re: VB script - List all user groups Help

    For the first remark, that is what I said: I have not tested

    Otherwise, I think the problem is triggered, occurs when the group does not belong to another group. We can solve this with the following correction:

    Code:
    Select All 
    Sub seekGrp(groupe) 
    Set objG = GetObject("LDAP:\\cn=" & groups & ",DC=...") 
    if IsArray(objG.MemberOf)   then 
    For Each grp in objG.MemberOf 
    strGroupsUser = strGroupsUser & grp 
    seekGrp(grp) 
    Next 
    end if 
    End Sub

  5. #5
    Join Date
    Nov 2008
    Posts
    21

    Re: VB script - List all user groups Help

    It's perfect, the code that you did work well.

    I still have 1 questions With this code, I can list the groups that are in the "Member" and groups that I describe as "second level". If I want to go further in search of groups I suppose, I must create another loop, but the place? I met the day code (code to search for a group of "" the first and second level "depending on the user logged in):

    Code:
    Select All 
    Set ADSysInfo = CreateObject("ADSystemInfo") 
    Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName) 
    strGroupsUser = LCase(Join(CurrentUser.MemberOf)) 
    For each grp in CurrentUser.MemberOf 
    seekGrp(grp) 
    Next 
    
    wscript.echo strGroupsUser 
    
    Sub seekGrp(groupe) 
    Set objG = GetObject("LDAP://"& groupe) 
    if IsArray(objG.MemberOf) then 
    For Each grp in objG.MemberOf 
    strGroupsUser = strGroupsUser & vbcrlf & LCase(grp) 
    seekGrp(grp) 
    Next 
    End if 
    End Sub

Similar Threads

  1. Replies: 6
    Last Post: 01-02-2011, 04:26 PM
  2. Script to create multiple groups
    By Saphire in forum Active Directory
    Replies: 1
    Last Post: 18-08-2008, 11:51 PM
  3. Ldap query to list groups a user is a member of?
    By SKREECH in forum Active Directory
    Replies: 1
    Last Post: 24-02-2008, 08:30 PM
  4. Getting a list of users in global and local groups.
    By Joe in forum Windows Server Help
    Replies: 10
    Last Post: 06-09-2007, 11:02 AM
  5. Script/regedit: Explorer-View-Arrange Icons by-Show In Groups...
    By prash_mate in forum Windows XP Support
    Replies: 1
    Last Post: 17-05-2007, 12:57 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,668,602.61372 seconds with 17 queries