Solved

AD Primary Group - LDAP problem

Posted on 2006-06-20
2
1,165 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

734 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