Solved

AD Primary Group - LDAP problem

Posted on 2006-06-20
2
1,160 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

13 Experts available now in Live!

Get 1:1 Help Now