Link to home
Start Free TrialLog in
Avatar of dcarrion
dcarrion

asked on

VBScript What groups user is member of

Hello

Just working on a script to return boolean if user is a member of group. However I want to go one step further and also list subgroups of groups etc...This is what I have at the moment


Private Function IsMember(groupName)
      Set netObj = CreateObject("WScript.Network")
      domain = "domain.local"
      user =  netObj.UserName
      flgIsMember = false
      Set userObj = GetObject("WinNT://" & domain & "/" & user & ",user")
      For Each grp In userObj.Groups
            if LCase(grp.Name) = LCase(groupname) then
                  flgIsMember=True      
                  Exit For
            end if
      Next
      IsMember = flgIsMember
      Set userObj = nothing
      Set netObj = nothing
End Function

I want it so I can go one step further in the For Loop so I can search subgroups as well...Any assistance would be much appreciated.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

You may want to remove this line:

WScript.Echo Space(x) & objGroup.Get("name")

It just echo's out the group names in a tree type format if you're running it with CScript on the command line.

Chris