get ALL Active Directory Groups a user belongs to

Posted on 2005-04-22
Medium Priority
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
  • 2
  • 2

Accepted Solution

defore earned 2000 total points
ID: 13843092
LVL 20

Expert Comment

ID: 13843929
Hi Kazung-Q,

I just had this come up on another forum.  Take a look here for the answer you are looking for - http://www.adminprep.com/forums/m_95/mpage_1/key_/tm.htm#96.  

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


Author Comment

ID: 13858330
@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

ID: 13858384
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

ID: 13858462

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


Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

862 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