get ALL Active Directory Groups a user belongs to

Posted on 2005-04-22
Last Modified: 2012-05-05

I want to get a list of ALL Active Directory a user belongs to: those he's in explicitely and the subgroups he's a member of.

userX is member of groupA, groupB and groupC and groupB is a member of groupD

I found following vbscript somwhere on the ww:
'Global Variables
Dim objShell, objNetwork, objFSO, objGroupDict

'Global Objects
Set objShell = CreateObject("Wscript.Shell")
Set objNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim sAdsPath, objUser, objGroup

Set objGroupDict = CreateObject("Scripting.Dictionary")
objGroupDict.CompareMode = vbTextCompare
sAdsPath = objNetwork.UserDomain & "/" & objNetwork.UserName
Set objUser = GetObject("WinNT://" & sAdsPath & ",user")

For Each objGroup In objUser.Groups
      objGroupDict.Add objGroup.Name, "-"
Set objUser = Nothing

but this script only returns the top-level groups a user belongs to. In this case groupA, groupB and groupC

I want to it to return groupD as well. Is this possible?
Question by:Kazung-Q
    LVL 3

    Accepted Solution

    LVL 20

    Expert Comment

    Hi Kazung-Q,

    I just had this come up on another forum.  Take a look here for the answer you are looking for -  

    Please let me know if there is anything else you need help with.


    Author Comment

    @Deforce just what I needed. Thanx! Remind me to take a course "VB-scripting"  ;o)
    thanx-a-lot the points are yours

    @mkbean: nice too, but I need it in .vbs (sorry)

    Author Comment

    ow no wait, it's excellent, but I want it the other way around actually:

    i start with a user-name and want al the groups he belongs to. This script starts with a group name & returns all members. I could implement it this way, but then I'll have to enumerate all members of all groups (in stead of all groups of 1 member) wich can't be good for logon performance .....
    LVL 20

    Expert Comment


    If you need this for a script you could just create a batch file and it will still get thte job done.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
    For Sennheiser, comfort, quality and security are high priority areas. This paper addresses the security of Bluetooth technology and the supplementary security that Sennheiser’s Contact Center and Office (CC&O) headsets provide.  
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now