Solved

AD Primary Group - LDAP problem

Posted on 2006-06-20
2
1,163 Views
Last Modified: 2008-01-09
I know how to take a users PrimaryGroupID and get the Primary Group that the user belongs to.  My problem is going the other way .... for example, taking the Domain Users group and trying to determine all users in that group (even the ones that have it set as their Primary Group).

What are some ways of doing this?  Is it something like getting all User objects in a Domain, then looping through all of them seeing which objects have that group set as their Primary group?
0
Comment
Question by:249Central
2 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 16950486
?

Dim grp
Dim memberList
Dim member

Set grp = GetObject("WinNT://yourdomain/yourdomaingrpname")
Set memberList = grp.members
For Each member In memberList
  Debug.Print member.Name & "(" & member.Class & ")"
Next
0
 
LVL 14

Accepted Solution

by:
dlwyatt82 earned 500 total points
ID: 16951672
Bind to the group and get the value of the "primaryGroupToken" attribute.  Then execute a search for users where "primaryGroupID = primaryGroupTokenValue":

'***************************

Set objGroup = GetObject("LDAP://CN=Whatever,DC=domain,DC=com")
objGroup.GetInfoEx Array("primaryGroupToken"), 0
intToken = objGroup.Get("primaryGroupToken")

Set objCon = CreateObject("ADODB.Connection")
Set objCmd = CreateObject("ADODB.Command")

objCon.Open "Provider=ADsDSOObject;"
Set objCmd.ActiveConnection = objCon

objCmd.CommandText = "SELECT sAMAccountName FROM 'LDAP://DC=domain,DC=com' WHERE " & _
    "objectCategory='person' AND objectClass='user' AND primaryGroupID='" & intToken & "'"

Set objRS = objCmd.Execute

Do While (Not objRS.EOF)
  WScript.Echo objRS("sAMAccountName")
  objRS.MoveNext
Loop
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

815 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

8 Experts available now in Live!

Get 1:1 Help Now