Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I extract the same employeeID attribute value that Outlook is displaying?

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?

Case 1: employeeID is different from ASP.Net than OutlookCase 2: employeeID is found in Outlook, but Nothing in ASP.Net

like image 464
Ahmad Avatar asked Dec 09 '13 13:12

Ahmad


2 Answers

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.

like image 81
Bo TX Avatar answered Oct 21 '22 18:10

Bo TX


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.....
like image 37
Mych Avatar answered Oct 21 '22 18:10

Mych