• Identify Members of a Group (03)

    Author
    Topic
    #431026

    Is it possible using VBA to identify the members of a group?

    Example: A selected folder’s security tab properties lists a group for rights/permissions. I am trying to identify who the individuals are in a group.

    Thanks,
    John

    Viewing 1 reply thread
    Author
    Replies
    • #1007906

      Depending on your configuration, something like this may work for you:

      Function ListMembers(strDomainName As String, strGroupName As String)
          Dim objGroup, objMember As Object
          Set objGroup = GetObject("WinNT://" & strDomainName & "/" & strGroupName & ",group")
          For Each objMember In objGroup.Members
              Debug.Print objMember.Name
          Next objMember
      End Function
      

      HTH

      • #1007923

        Rory,

        Thanks for the code. This is exactly what I was looking for.

        John

      • #1176201

        For Each objMember In objGroup.Members
        Debug.Print objMember.Name
        Next objMember
        HTH

        Rory,

        What other objMember definitions are available to the members? I know that one can obtain objMember.Name and objMember.FullName.

        Thanks,
        John

        • #1176238

          What other objMember definitions are available to the members? I know that one can obtain objMember.Name and objMember.FullName.

          If you add a Stop statement after instantiating the object (e.g., just inside the For Each loop) and open the Locals window, you may be able to browse the object’s properties and gain more insight. Any luck?

    • #1176295

      This should give some idea. Not all properties are always available:

      Code:
      Function ListMembers(strDomainName As String, strGroupName As String)
      Dim objGroup, objMember As IADsUser
      Set objGroup = GetObject("WinNT://" & strDomainName & "/" & strGroupName & ",group")
      For Each objMember In objGroup.Members
         With objMember
      	  Debug.Print .AccountDisabled
      	  Debug.Print .AccountExpirationDate
      	  Debug.Print .ADsPath
      	  Debug.Print .BadLoginAddress
      	  Debug.Print .BadLoginCount
      	  Debug.Print .Class
      	  Debug.Print .Department
      	  Debug.Print .Description
      	  Debug.Print .Division
      	  Debug.Print .EmailAddress
      	  Debug.Print .EmployeeID
      	  Debug.Print .FaxNumber
      	  Debug.Print .FirstName
      	  Debug.Print .FullName
      	  Debug.Print .GraceLoginsAllowed
      	  Debug.Print .GraceLoginsRemaining
      	  Debug.Print .GUID
      	  Debug.Print .HomeDirectory
      	  Debug.Print .HomePage
      	  Debug.Print .IsAccountLocked
      	  Debug.Print .Languages
      	  Debug.Print .LastFailedLogin
      	  Debug.Print .LastLogin
      	  Debug.Print .LastLogoff
      	  Debug.Print .LastName
      	  Debug.Print .LoginHours
      	  Debug.Print .LoginScript
      	  Debug.Print .LoginWorkstations
      	  Debug.Print .Manager
      	  Debug.Print .MaxLogins
      	  Debug.Print .MaxStorage
      	  Debug.Print .Name
      	  Debug.Print .NamePrefix
      	  Debug.Print .NameSuffix
      	  Debug.Print .OfficeLocations
      	  Debug.Print .OtherName
      	  Debug.Print .Parent
      	  Debug.Print .PasswordExpirationDate
      	  Debug.Print .PasswordLastChanged
      	  Debug.Print .PasswordMinimumLength
      	  Debug.Print .PasswordRequired
      	  Debug.Print .Picture
      	  Debug.Print .PostalAddresses
      	  Debug.Print .PostalCodes
      	  Debug.Print .Profile
      	  Debug.Print .RequireUniquePassword
      	  Debug.Print .Schema
      	  Debug.Print .SeeAlso
      	  Debug.Print .TelephoneHome
      	  Debug.Print .TelephoneMobile
      	  Debug.Print .TelephoneNumber
      	  Debug.Print .TelephonePager
      	  Debug.Print .Title
         End With
      Next objMember
      End Function
      • #1176506

        Rory,

        Taking this one step further, I created an array of the 53 properties and would like to pass each of the 53 properties to the “Debug.Print” line.

        My code looks like this:

        [codebox]Function ListMembers(strDomainName As String, strGroupName As String)
        Dim objGroup, objMember As Object
        Dim myArray

        Set objGroup = GetObject(“WinNT://” & strDomainName & “/” & strGroupName & “,group”)

        myArray = Array(“FullName”, “Name”) ‘Kept the 53 properties to two for testing purposes

        For Each objMember In objGroup.Members

        With objMember
        Debug.Print objMember.FullName ‘This Line works without variable from array being passed through
        Debug.Print objMember & “.” & myArray(1) ‘This is where I get hung up
        End With
        Next objMember
        [/codebox]
        ‘more code follows…

        Thanks for your assistance,
        John

        • #1176533

          You’ll need to use CallByName
          [codebox]Function ListMembers(strDomainName As String, strGroupName As String)
          Dim objGroup, objMember As Object
          Dim myArray

          Set objGroup = GetObject(“WinNT://” & strDomainName & “/” & strGroupName & “,group”)

          myArray = Array(“FullName”, “Name”) ‘Kept the 53 properties to two for testing purposes

          For Each objMember In objGroup.Members

          With objMember
          Debug.Print CallByName(objMember, myArray(1), VbGet)
          End With
          Next objMember
          [/codebox]

    Viewing 1 reply thread
    Reply To: Identify Members of a Group (03)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: