Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Active Directory

Status
Not open for further replies.

spawnwest

Programmer
Apr 10, 2001
5
US
I am trying to create a phone search using active directory. For example if you search "Tim", I would like to display the name and phone for every user who's first name is Tim. The code I current have will retrieve the groups and displayName of the current logged on users. How would I modify this code. Any suggestions? Thanks!

Tim

Dim sPath As String = "LDAP://mydomain.com/DC=mydomain,DC=com"
Dim SamAccount As String = Right(inSAM, Len(inSAM) - InStr(inSAM, "\"))
Dim myDirectory As New DirectoryEntry(sPath, "Administrator", "Password")
Dim mySearcher As New DirectorySearcher(myDirectory)
Dim mySearchResultColl As SearchResultCollection
Dim mySearchResult As SearchResult
Dim myResultPropColl As ResultPropertyCollection
Dim myResultPropValueColl As ResultPropertyValueCollection

'Build LDAP query
mySearcher.Filter = ("(&(objectClass=user)(samaccountname=" & SamAccount & "))")
mySearchResultColl = mySearcher.FindAll()

'I expect only one user from search result
Select Case mySearchResultColl.Count
Case 0
Return "Null"
Exit Function
Case Is > 1
Return "Null"
Exit Function
End Select

'Get the search result from the collection
mySearchResult = mySearchResultColl.Item(0)

Dim i As Integer
Dim iCount As Integer = mySearchResult.Properties("MemberOf").Count

'Get groups user belong to
For i = 0 To iCount - 1
Dim gADs As String = mySearchResult.Properties("MemberOf").Item(i)
Dim myGroup As String = Left(gADs, (InStr(gADs, ",") - 1))
Next

'Get the Properites, they contain the usefull info
myResultPropColl = mySearchResult.Properties

'displayname, mail
'Retrieve from the properties collection the display name and email of the user
myResultPropValueColl = myResultPropColl.Item(inType)
Return CStr(myResultPropValueColl.Item(0))

Catch ex As System.Exception
Response.Write("Error: " & ex.ToString())
Response.End
End Try
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top