Solved

VB, Search Active Directory based on Login ID

Posted on 2004-08-03
4
184 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
Comment Utility
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
Comment Utility
I've tried the following code and I get the following error: "Table does not exist"
0
 

Author Comment

by:eciabattari
Comment Utility
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
Comment Utility
glad you got it eci
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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 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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 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

11 Experts available now in Live!

Get 1:1 Help Now