Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB, Search Active Directory based on Login ID

Posted on 2004-08-03
4
Medium Priority
?
205 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
[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
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
gilbar earned 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Suggested Courses

730 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