Solved

VB, Search Active Directory based on Login ID

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

809 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