; ======================================================================
; Check Group Membership - the arg can be a comma-delimited list of groups
; Membership in any listed group will return TRUE
Function fInGroup($_Group)
Dim $_I ; Index Var
Dim $_C ; Count of matched groups
Dim $_oSys, $_oTarget ; Connection Objects
Dim $_aMemberOf, $_MemberOf ; Array of groups, enumerator
Dim $_aGroups ; array of groups that the user is a member of
$fInGroup = 0 ; default FALSE
$_C = -1 ; no memberships
$_I = -1
Do
$_I = $_I + 1
ReDim Preserve $_aGroups[$_I]
$_aGroups[$_I] = ENUMGROUP($_I)
If InStr($_aGroups[$_I], '\')
$_aGroups[$_I] = Split($_aGroups[$_I], '\')[1]
EndIf
Until EnumGroup($_I) = ''
$_I = $_I - 1
$_oSys = CreateObject('ADSystemInfo') ; instantiate connection
$_oTarget = GetObject('LDAP://' + $_oSys.UserName) ; Connect to AD
$_aMemberOf = $_oTarget.GetEx('memberOf') ; Get list of groups
For Each $_MemberOf in $_aMemberOf
$_MemberOf = Split(Split($_MemberOf, '=')[1], ',')[0]
If AScan($_aGroups, $_MemberOf) = -1
$_I = $_I + 1
ReDim Preserve $_aGroups[$_I]
$_aGroups[$_I] = $_MemberOf
EndIf
Next
$_aInGroups = Split($_Group, ',')
For Each $_Group in $_aInGroups
If AScan($_aGroups, $_Group) > -1
$_C = $_C + 1
EndIf
Next
If $_C > -1 $fInGroup = 1 EndIf
Exit Not $fInGroup
EndFunction