troubleshooting Question

VBscript to determine group membership recursively

Avatar of metropolitanhotel
metropolitanhotel asked on
VB Script
9 Comments1 Solution1867 ViewsLast Modified:
I'm moving to a recursive group structure in AD that will be as follows:
  - Department
    - Job Function

Now, user accounts will only be added to the bottom group, their job function, and they inherit the group permissions etc for their department and site.  Now, I'm writing a fairly long login script in VBscript that does certain things based on either site or department, but rarely job function.  I have a small function that I found in someone else's loging script that does a great job of determining if a user is in a group, but it doesn't work for the scenario above, as the user would need to be a member of all 3 groups for it to apply to them.

The function I have is:

Function IsMember(sGroup)
    Dim oDict, oUser, oGroup

    If IsEmpty(oDict) Then
        Set oDict = CreateObject("Scripting.Dictionary")
        oDict.CompareMode = vbTextCompare
        Set oUser = GetObject("WinNT://" & strAdsPath & ",user")
        For Each oGroup In oUser.Groups
            oDict.Add oGroup.Name, "-"
        Set oUser = Nothing
    End If
    IsMember = CBool(oDict.Exists(sGroup))
    if IsMember and bolWriteLog then objLogFile.WriteLine(Now() & ": Success: User is member of " & sGroup)
End Function

What I need is one that can somehow tell that if the account is in a group called "Accounts - Managers", then that group in in the group "Accounts Department".  Perhaps there is another way to accomplish the same thing that I haven't thought of.

Thanks in advance :-)
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros