;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       ComputerInGroup() 
;; 
;;ACTION         Checks the local computer for membership in one or more groups 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.0  - 2010/01/22 
;; 
;;HISTORY        1.0  - 2010/01/22 - Initial Release 
;; 
;;SYNTAX         ComputerInGroup(Groups) 
;; 
;;PARAMETERS     Groups - REQUIRED - a list of one or more group names 
;;               Can be a single text value, a comma-delimited list of group names, 
;;               or an array of group names. 
;; 
;;REMARKS        Checks AD/LDAP to determine if the computer is a member of any of 
;;		 the group(s) listed.  
;; 
;;RETURNS        1 if a membership match is found, 0 if not 
;; 
;;DEPENDENCIES   none 
;; 
;;TESTED WITH    W2K, WXP, W2K3 
;; 
;;EXAMPLES       $PCGroups = 'Sales', 'Marketing' 
;;		 If ComputerInGroup($PCGroups) 
;;		   'Is sales or marketing PC!' ? 
;;		 EndIf 
; 
Function ComputerInGroup($_GroupName)
 
  Dim $_objSysInfo, $_objComputer		; object pointers 
  Dim $_Groups,$_Group				; groups array, enumerator 
 
  $ComputerInGroup = 0
 
  $_objSysInfo  = CreateObject('ADSystemInfo')
  $_objComputer = GetObject('LDAP://' + $_objSysinfo.computername)
  $_Groups = $_objComputer.GetEx('memberOf')
 
  ; if array was passed, translate to a simple list 
  If VarType($_GroupName) > 8191
    $_GroupName = Join($_GroupName, ',')
  EndIf
 
  ; Add delimiters to the argument 
  $_GroupName = ',' + $_GroupName + ','
  ; enumerate the array of groups 
  For Each $_Group in $_Groups
    ; if the delimited group name is part of the argument (list), return true 
    If InStr($_GroupName, ',' + GetObject('LDAP://' + $_Group).cn + ',')
      $ComputerInGroup = 1
      Exit 0
    EndIf
  Next
 
  Exit 0
 
EndFunction