Solved

AD Primary Group - LDAP problem

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb6 programatically bring window to front 8 63
VBA to copy paste columns form one file to other 20 85
Determine Range to Select 5 42
Set email body to html using vbscript 6 26
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now