; 
;=====================================================================================----- 
; 
; 
;FUNCTION    GroupMembers() 
; 
;ACTION      Returns an array of all group members of the specified group 
; 
;AUTHOR      Bryce 
; 
;VERSION     1.0 - 2001/11/26  
; 
;HISTORY     1.0 - 2001/11/26 - Initial Release 
; 
;SYNTAX      GroupMembers(Target, Group, [FLAG]) 
; 
;PARAMETERS  Target - Required - String 
;            - The Domain name or Workstation to work with.  For faster workstation  
;             execution, include the Domain Name that the workstation is a meber of. 
; 
;             "Kixtart/beanbag" would be working with the workstation Beanbag in the  
;             Kixtart domain 
; 
;            Group - Required - String 
;            - The Group you want to query 
; 
;            Flags - Optional - Integer 
;            - To use the flags options add the numbers of the desired flags toghther 
;            and use that number in the flag field. 
; 
;           Filter (only one filter flag at a time please) 
;                     1 = all 
;                     2 = Users only 
;                     4 = Groups only 
; 
;           ADSI Information(return ADSI information "pick only one") 
;                     8  = ADSPath field 
;                     16 = ADSI Object Handle 
; 
;RETURNS     array, if the ADSPath option is used the ADSPath  
;            will also be returned. 
; 
;REMARKS     ADSI com object must be installed. 
; 
;EXAMPLES    ;this return all members of the Domain Admins group in the kixtart domain. 
;            $members = groupmembers("kixtart","Domain admins") 
; 
;            ;this will will return all groups in the local administrators group on  
;            ;the Workstation beanbad in the kixtart domain.  Also the  
;            $_groups = groupmembers("kixtart/beanbag","Administratoos","group") 
Function Groupmembers($_Target, $_group, optional $_Flag)
 
  Dim $_Temparray[8], $_Member, $_I, $_Chunk, $_ADSIFlag, $_FilterFlag
 
  $_Chunk = UBound($_Temparray)
  $_Flag = Val($_Flag)
  $_I = 0
  $_Group = GetObject('WinNT://' + $_Target + '/' + $_Group)
 
  If VarType($_Group) <> 9 Exit @ERROR EndIf
 
  Select
   Case $_Flag & 1
    $_FilterFlag = 1
   Case $_Flag & 2
    $_FilterFlag = 2
   Case $_Flag & 4
    $_FilterFlag = 4
   Case 1
    $_FilterFlag = 1
  EndSelect
 
  Select
   Case $_Flag & 8
    $_ADSIFlag = 8
   Case $_Flag & 16
    $_ADSIFlag = 16
  EndSelect
 
  For Each $_Member in $_Group.members
    Select
     Case $_FilterFlag = 2 AND $_Member.class = "user"
      If substr($_Member.name,len($_Member.name),1) <> Chr(36)
        $_Temparray[$_I] = $_Member.name
 
        Select
         Case $_adsIflag = 8
          $_Temparray[$_I] = $_Member.adspath
         Case $_adsIflag = 16
          $_Temparray[$_I] = $_Member
        EndSelect
 
        $_I = $_I + 1
 
      EndIf
 
     Case $_FilterFlag = 4 AND $_Member.class = "Group"
      If substr($_Member.name,len($_Member.name),1) <> Chr(36)
        $_Temparray[$_I] = $_Member.name
 
        Select
         Case $_adsIflag = 8
          $_Temparray[$_I] = $_Member.adspath
         Case $_adsIflag = 16
          $_Temparray[$_I] = $_Member
        EndSelect
 
        $_I = $_I + 1
 
      EndIf
 
     Case $_FilterFlag = 1
      If substr($_Member.name,len($_Member.name),1) <> Chr(36)
        $_Temparray[$_I] = $_Member.name
 
        Select
         Case $_adsIflag = 8
          $_Temparray[$_I] = $_Member.adspath
         Case $_adsIflag = 16
          $_Temparray[$_I] = $_Member
        EndSelect
 
        $_I = $_I + 1
 
      EndIf
 
     Case $_FilterFlag
      ;bit bucket 
 
    EndSelect
 
    If $_I = ubound($_Temparray)
      Redim Preserve $_Temparray[Ubound($_Temparray) + $_Chunk]
    EndIf
 
  Next
 
  If $_I <> 0
    Redim Preserve $_Temparray[$_I - 1]
    $Groupmembers = $_Temparray
  EndIf
 
  Exit 0
 
Endfunction