Search code examples
vbscripthtaldap-query

LDAP Group object loop


I have an HTA file that just hangs on a process of me looping through group entries from an LDAP query.

Set objUser = GetObject("LDAP://" & strUserDN) 

For Each objGroup In objUser.Groups
    If "wifi user" = lcase(replace(objGroup.Name,"CN=","")) Then
        'modify my dom element here....
    End If
    If "encryption enabled" = lcase(replace(objGroup.Name,"CN=","")) Then
        'modify my dom element here....
    End If
    If "dl - some office" = lcase(replace(objGroup.Name,"CN=","")) Then
        'modify my dom element here....
   End If
Next

Is there a more efficient way to iterate through these groups, 80+ is a range of groups its looping and causing problems.

Or maybe I try to dump the whole list to a string and do an InStr query on it?


Solution

  • the below code change had a dramatic improvement where looping through just a named list vs the entirety of a single group object. my PowerShell logic kicked in and got me here along with @Ansgar Wiechers prodding of testing it deeper. Thanks!

    Set objUser = GetObject("LDAP://" & strUserDN) 
    
    arrGroup = objUser.MemberOf
                strGroup = ""
                For i = 0 To UBound(arrGroup)
                    strGroup = arrGroup(i)
    
                    If InStr(lcase(strGroup),"vpn user") Then
                        WScript.echo "block grp 1"
                    End If
                    If InStr(lcase(strGroup),"dl - some office") Then
                        WScript.echo "block grp 2"
                    End If
                    If InStr(lcase(strGroup),"encryption enabled") Then
                        WScript.echo "block grp 3"
                    End If
                    If InStr(LCase(strGroup), "wireless") Then
                        strWifi = True 
                    End If 
                Next