Solved

VB, Search Active Directory based on Login ID

Posted on 2004-08-03
4
188 Views
Last Modified: 2011-10-03
Hi - Need some help.  I need to search our company Active Directory based on Login ID and then check if the user is a member is part of a particular group.

Example: EVCI
Group membership: boc ctgg-documentum-finance

Can anyone assist?

Thanks





0
Comment
Question by:eciabattari
  • 2
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
gilbar earned 500 total points
ID: 11706787
here's a script:

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = _
 "<GC://cn=g_test,ou=global groups,ou=abc users,dc=abc,dc=com>;(objectCategory=Group);" & _
 "distinguishedName,name,member;subtree"

Set objRecordSet = objCommand.Execute

While Not objRecordSet.EOF
 Wscript.Echo objRecordSet.Fields("Name")
 Wscript.Echo "[" & _
 objRecordSet.Fields("distinguishedName") & "]"

 Wscript.Echo "Group Member(s):"
 arrMembers = objRecordSet.Fields("member")

 If IsArray(objRecordSet.Fields("member")) Then
 For Each strMember in arrMembers
 Wscript.Echo vbTab & strMember
 Next
 Else
 Wscript.Echo vbTab & "None"
 End If
 Wscript.Echo VbCrLf
 objRecordSet.MoveNext
Wend

objConnection.Close


it shows the members of global group g_test, which is in the organizational unit global groups, which is in the organizational unit abc users, which is in the abc.com forest (or tree?) the output looks something like this:

g_AAReadyToTest
[CN=g_AAReadyToTest,OU=z_EMCINS Global Groups,OU=EMC Users,DC=EMCINS,DC=com]
Group Member(s):
        CN=Ross,OU=Data,OU=Data Processing,OU=Home Office
,OU=abc Users,DC=abc,DC=com
        CN=Dawn,OU=Data,OU=Data Processing,OU=Home Office,
OU=abc Users,DC=abc,DC=com


hope this helps!

0
 

Author Comment

by:eciabattari
ID: 11716204
I've tried the following code and I get the following error: "Table does not exist"
0
 

Author Comment

by:eciabattari
ID: 11719927
The following code did what I wanted.  Thanks

'---------------------------------------------------------------------------------------------------------------
Public Function MembersOfGroup(strGroup, strDomain, strMember As String) As Boolean
    Dim adsGroup As ActiveDs.IADsGroup
    Dim adsMembers As ActiveDs.IADsMembers
    Dim adsMember As Object
    Dim strMemberName As String
       
On Error Resume Next

    Set adsGroup = GetObject("WinNT://" + strDomain + "/" + strGroup)

    MembersOfGroup = False

If Err.Number = 0 Then

    Err.Clear
    On Error GoTo 0
   
    Set adsMembers = adsGroup.Members
    Set oCol = New Collection
   
    adsMembers.Filter = Array("Members")

    For Each adsMember In adsMembers
       
        If adsMember.Name = strMember Then
            MembersOfGroup = True
            Exit For
        End If
       
        If adsMember.Name = strUserName Then
            strGroupMembers = "1"
        End If
       
    Next adsMember
   
    Set adsMember = Nothing
    Set adsMembers = Nothing
    Set adsGroup = Nothing
End If

End Function
'---------------------------------------------------------------------------------------------------------------
0
 
LVL 9

Expert Comment

by:gilbar
ID: 11719951
glad you got it eci
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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

914 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

21 Experts available now in Live!

Get 1:1 Help Now