Our company uses ActiveDirectory for various reasons. One of them is to handle Outlook contacts and user log-in IDs.
I have written a program to detect the logged in user id, and to search the Active Directory using the extracted login id. The pulled information from the Active Directory is then stored in a database.
Here is the code I used to pull ActiveDirectory information data:
Dim enTry As DirectoryEntry = _
New DirectoryEntry("LDAP://myCOMPANY/DC=myCOMPANY,DC=myCOMPANY,DC=com")
Dim mySearcher As DirectorySearcher = New DirectorySearcher(enTry)
mySearcher.Filter = "(&(objectClass=user)(anr=" & thisUser & "))"
'thisUser is the variable holding the Windows ID that is accessing the ASPX page
mySearcher.PropertiesToLoad.Add("employeeID") 'just in case I need to do this.
Dim resEnt As SearchResult
Try
For Each resEnt In mySearcher.FindAll()
Dim fullname As String = resEnt.GetDirectoryEntry.Properties.Item("cn").Value
'fullname will always pull the right information
Dim e_id As String = resEnt.GetDirectoryEntry.Properties.Item("employeeID").Value
'e_id will sometimes be NOTHING, sometimes will contain an ID that
' is different from the one displayed in Outlook Contact Information
' and sometimes it will be matching the employeeID listed in Outlook info
Catch ex as Exception
Log("Failed to pull AD data: " & ex.Message)
End Try
For some reason, some users have no values for their employeeID field, and some have.
However, all of the users, will display an employeeID value when browsed in Outlook.
I designed the following image to help you understand what I am going through. The image is divided into two sections, a section for each CASE.
========================================================
In Case 1, the employee has logged in to Windows using his ID: xms33808
Outlook shows that his Employee ID is 16078
Outlook shows that his email alias is xms33808
ASP.Net command window shows that his employeeID is xms33808
, which is not true
======================================================
=======================================================
In Case 2, the employee has logged in to Windows using ID: 25163
Outlook shows that his Employee ID is 25163
Outlook shows that his email alias is MutawaAAB
ASP.Net command windows shows that his employeeID is NOTHING
.
=======================================================
My question is : How can I extract the same employeeID value information that Outlook is displaying?
There is a confusingly similar AD Attribute called 'employeeNumber'. Could it be that Outlook is actually using this property to populate it's display?
Per this Microsoft Support page on Outlook Contact Cards, 'employeeID' is not a field that you can use. However, 'employeeNumber' is.
http://support.microsoft.com/kb/981022
Hope this helps at least advance your troubleshooting efforts.
If you use .net 3.5 or above you can use the following which is much easier than LDAP etc...
Add a reference and an Imports statement for System.DirectoryServices.AccountManagement
To get details for a specific user:
Dim objPC As PrincipalContext = Nothing
Dim objADUser As UserPrincipal = Nothing
Try
objPC = New PrincipalContext(ContextType.Domain, "YourDomain")
objADUser = UserPrincipal.FindByIdentity(objPC, "NetworkLogin")
Catch ex As Exception
End Try
To get details for the currently logged on user
Dim objADUser As UserPrincipal = Nothing
Try
objADUser = UserPrincipal.Current
Catch ex As Exception
End Try
You can then interrogate the object objADUser and get all sorts of details such as
objADUser.VoiceTelephoneNumber
objADUser.EmailAddress
objADUser.EmployeeNumber and many others.....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With