Windows Vista Forums

Count a users groups

  1. #1


    Gunna Guest

    Count a users groups

    Hi,



    Im tying to enumerate the members of a partiular group and then for each
    member of that group count the total number of groups they belong too. I
    think im right to enumerate the group members and then I figured id need to
    do some kind of action for each member of the group to count the number of
    groups they belong too.

    Can anyone offer some guidance?

      My System SpecsSystem Spec

  2. #2


    Richard Mueller [MVP] Guest

    Re: Count a users groups


    "Gunna" <Gunna@xxxxxx> wrote in message
    news:A34E5035-C15D-4F5A-998E-93B543926436@xxxxxx

    > Hi,
    >
    > Im tying to enumerate the members of a partiular group and then for each
    > member of that group count the total number of groups they belong too. I
    > think im right to enumerate the group members and then I figured id need
    > to
    > do some kind of action for each member of the group to count the number of
    > groups they belong too.
    >
    > Can anyone offer some guidance?
    If you bind to the group you can use the Members method of the group object
    to enumerate all direct members. The Members method returns a collection of
    object references to the members, so you can retrieve other information
    about the members. For example, you can use the memberOf attribute of each
    member object to enumerate the DN's of the groups they are members of. There
    is no way to retrieve a count, so you must enumerate each DN and count. For
    example:
    ==========
    Option Explicit

    Dim objGroup, objMember, strGroup, lngCount

    Set objGroup = GetObject("LDAP://cn=MyGroup,ou=West,dc=MyDomain,dc=com")

    For Each objMember In objGroup.Members
    lngCount = 0
    For Each strGroup In objMember.memberOf
    lngCount = lngCount + 1
    Next
    Wscript.Echo objMember.sAMAccountName & " is a member of " _
    & CStr(lngCount) & " groups."
    Next

    --
    Richard Mueller
    MVP Directory Services
    Hilltop Lab - http://www.rlmueller.net
    --



      My System SpecsSystem Spec

Count a users groups

Similar Threads
Thread Thread Starter Forum Replies Last Post
SBS2k8 Users and Groups tab yaro137 SBS Server 1 26 Jan 2010
Remove groups from users Shawn PowerShell 2 19 Dec 2008
Users&Groups Network Location Awareness Not Starting Vista General 2 10 Dec 2007
How to do sysprep to make a image for my users and maintain the count on KMS server ? Motor Wu Vista installation & setup 5 20 Mar 2007
How to do sysprep to make a image for my users and maintain the count on KMS server ? Motor Wu Vista General 2 15 Mar 2007