Solved

VB, Search Active Directory based on Login ID

Posted on 2004-08-03
4
193 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

808 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