Q: which one is AD server


G

Guest

Hello,

I have this code to retrieve Active Directory information, When I click
button1 I get an exception at oResults = oSearcher.FindAll saying “the server
is not operationalâ€. Which server name should I pass? I do not know much
about in our network but I am sending one of the server name in our
environment which I can reach active directory.
Thanks,
Jim.



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
GetAllUsers("MyServer")
End Sub

Public Function GetAllUsers(ByVal ldapServerName As String) As Hashtable

'To retrieve list of all LDAP users

'This function returns HashTable
_ldapServerName = ldapServerName

Dim sServerName As String = "mail"

Dim oRoot As DirectoryEntry = New DirectoryEntry("LDAP://" &
ldapServerName & "/ou=People,dc=MyDomain,dc=net")

Dim oSearcher As DirectorySearcher = New DirectorySearcher(oRoot)
Dim oResults As SearchResultCollection
Dim oResult As SearchResult
Dim RetArray As New Hashtable

Try

oSearcher.PropertiesToLoad.Add("uid")
oSearcher.PropertiesToLoad.Add("givenname")
oSearcher.PropertiesToLoad.Add("cn")
oResults = oSearcher.FindAll

For Each oResult In oResults

If Not oResult.GetDirectoryEntry().Properties("cn").Value =
"" Then

RetArray.Add(oResult.GetDirectoryEntry().Properties("uid").Value, _
oResult.GetDirectoryEntry().Properties("cn").Value)
End If

Next

Catch e As Exception

Response.Write("Error is " & e.Message)
Return RetArray

End Try

Return RetArray

End Function
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top