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

active-directory, asp.net, ldap, outlook, vb.net

Solution

I finally found the attribute that is holding the employee ID.

For those looking for an answer to the same question, here is the name of the attribute:

`extensionattribute2`

The way I came across this is by printing out all attribute values held by the search entry result..

For Each resEnt In mySearcher.FindAll()
    Debug.Print("The properties of the " + resEnt.GetDirectoryEntry().Name + " are :")
        For Each singleAttribute As String In DirectCast(resEnt.Properties, ResultPropertyCollection).PropertyNames
            Debug.Print(singleAttribute & Convert.ToString(" = "))
            For Each singleValue As [Object] In DirectCast(resEnt.Properties, ResultPropertyCollection)(singleAttribute)
                Debug.Print(vbTab + singleValue.ToString)
            Next
        Next
Next

Then I examined the output and found the badge number printed out next to `extensionattribute2` ..

Very strange name for a property that should be called `employeeID` or `staffID` or `BadgeNumber` or anything else that makes sense.

Later on, I modified my code that searches the Active Directory to search not only by the Sama Account, but also by this `extensionattribute2` thing too since each employee has a unique ID.

Dim LookFor As String = "25163"
Dim mySearcher As DirectorySearcher = New DirectorySearcher(enTry)

mySearcher.Filter = "(&(| (anr=" & LookFor & ")" & _ 
                         "(extensionattribute2=" & LookFor & "))" & _ 
                         "(objectCategory=Person)(objectClass=user))"

Problem

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?

Original source