Hi All,
I am trying to retrieve the telephone number from Active Directory for my script, I found alot of examples online, and I tried to implement what I think should make sense (but since I really don't know vb that well, this is problematic). Below is the piece of code:
.
.
.
''''Get Phone Number from Active Directory using employee ID retrieved from the logged in user
Dim dirEntry, de As DirectoryEntry
Dim dirSearcher As DirectorySearcher
Dim sr As SearchResult
dirEntry = New System.DirectoryServices.DirectoryEntry("LDAP://company.com")
dirSearcher = New System.DirectoryServices.DirectorySearcher(dirEntry)
dirSearcher.Filter = "(employeeID = " & Me.fp.BadgeNo & ")"
'The PropertiesToLoad.Add method will be useful when retrieving only the selected properties.
dirSearcher.PropertiesToLoad.Add("telephoneNumber")
'Users Phone
sr = dirSearcher.FindOne()
If sr Is Nothing Then 'return false if user isn't found
Me.tb_phone.Text = "N/A"
End If
'Retrieve the user's Phone Number and assigns them to text boxes
de = sr.GetDirectoryEntry()
If Not de.Properties("telephoneNumber").Value Is Nothing Then
Me.tb_phone.Text = de.Properties("telephoneNumber").Value.ToString()
End If
.
.
.
After running the script, I am getting the following error: "An operations error occurred" and the error always points to: "sr = dirSearcher.FindOne()"
Please help
Maydhya