Hi all,
Note that I'm new to LDAP and Active Directory and am writing an application that retrieves a simple phone list for all the users in our domain. So far I have the following console app code that seems to work. It queries Active Directory for a phone list and correctly retrieves the names (cn) from the OU. Though I have asked for properties like telephoneNumber , homeNumber, mobile, ipphone, facsimileTeleph oneNumber...the properties are all populated by the land line i.e. telephoneNumber . e.g.
User: John Doe, Phone: 3256 2222, Home: 3256 2222, Cell: 3256 2222, IPPhone: 3256 2222, Fax: 3256 2222
User: Jane Doe, Phone: 5556 2222, Home: 5556 2222, Cell: 5556 2222, IPPhone: 5556 2222, Fax: 5556 2222
Ideally they should populate with the correct fax, mobile no e.g.
User: John Doe, Phone: 3256 2222, Home: 3256 1234, Cell: 0256 221356, IPPhone: n/a, Fax: 3256 2258
User: Jane Doe, Phone: 5556 2222, Home: 5556 1253, Cell: 0325 788356, IPPhone: 782145 , Fax: n/a
etc
I don't know where I'm going wrong and would appreciate any assistance. The code is as below:
____________
regards
Hems
Note that I'm new to LDAP and Active Directory and am writing an application that retrieves a simple phone list for all the users in our domain. So far I have the following console app code that seems to work. It queries Active Directory for a phone list and correctly retrieves the names (cn) from the OU. Though I have asked for properties like telephoneNumber , homeNumber, mobile, ipphone, facsimileTeleph oneNumber...the properties are all populated by the land line i.e. telephoneNumber . e.g.
User: John Doe, Phone: 3256 2222, Home: 3256 2222, Cell: 3256 2222, IPPhone: 3256 2222, Fax: 3256 2222
User: Jane Doe, Phone: 5556 2222, Home: 5556 2222, Cell: 5556 2222, IPPhone: 5556 2222, Fax: 5556 2222
Ideally they should populate with the correct fax, mobile no e.g.
User: John Doe, Phone: 3256 2222, Home: 3256 1234, Cell: 0256 221356, IPPhone: n/a, Fax: 3256 2258
User: Jane Doe, Phone: 5556 2222, Home: 5556 1253, Cell: 0325 788356, IPPhone: 782145 , Fax: n/a
etc
I don't know where I'm going wrong and would appreciate any assistance. The code is as below:
Code:
Imports System.DirectoryServices Imports System.DirectoryServices.ActiveDirectory Imports System Imports System.Collections Imports System.Collections.Specialized Module Module1 Sub Main() Dim LDAP As String = "LDAP://OU=Perth,DC=cnn,DC=com,DC=au" (This is an example, use your own domain e.g."LDAP://CNN". Dim origWidth, width As Integer Dim origHeight, height As Integer origWidth = Console.WindowWidth origHeight = Console.WindowHeight width = origWidth * 1.5 height = origHeight * 2.5 Console.SetWindowSize(width, height) Dim entry As New DirectoryEntry(LDAP, Nothing, Nothing, DirectoryServices.AuthenticationTypes.Secure) Dim ADSearcher As New DirectorySearcher(entry) ADSearcher.Filter = "(&(objectCategory=person)(objectClass=user))" '"(objectCategory=person)" With ADSearcher .SearchRoot = entry .PropertiesToLoad.Add("telephoneNumber") .PropertiesToLoad.Add("homeNumber") .PropertiesToLoad.Add("mobile") .PropertiesToLoad.Add("ipphone") .PropertiesToLoad.Add("facsimileTelephoneNumber") .PropertiesToLoad.Add("cn") End With Dim adColl As System.DirectoryServices.SearchResultCollection Dim Phone, Cell, Home, IPhone, Fax, CN As System.DirectoryServices.ResultPropertyValueCollec tion Try adColl = ADSearcher.FindAll() Dim i As Integer For i = 0 To adColl.Count - 1 Dim adEntry As SearchResult = adColl(i) Phone = adEntry.Properties("telephoneNumber") Home = adEntry.Properties("homeNumber") Cell = adEntry.Properties("mobile") iphone = adEntry.Properties("ipphone") Fax = adEntry.Properties("facsimileTelephoneNumber") CN = adEntry.Properties("cn") Dim user As String = CN.Item(0) Dim phoneNumber As String = "" Dim homeNumber As String = "" Dim cellNumber As String = "" Dim ipphone As String = "" Dim Fx As String = "" Try phoneNumber = Phone.Item(0).ToString homeNumber = Phone.Item(0).ToString cellNumber = Phone.Item(0).ToString ipphone = Phone.Item(0).ToString Fx = Phone.Item(0).ToString Catch ex As Exception 'No phone number exists. phoneNumber = "n/a" homeNumber = "n/a" cellNumber = "n/a" ipphone = "n/a" Fx = "n/a" End Try Console.WriteLine(String.Format("User: {0}, Phone: {1}, Home: {2}, Cell: {3}, IPPhone: {4}, Fax: {5}", user, phoneNumber, homeNumber, cellNumber, ipphone, Fx)) Next i Console.ReadLine() Catch ex As Exception Console.WriteLine(ex.Message.ToString) Finally adColl.Dispose() ADSearcher.Dispose() entry.Dispose() End Try End Sub End Module
regards
Hems
Comment