473,324 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Active Directory LDAP Phone List app

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, facsimileTelephoneNumber...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:

Expand|Select|Wrap|Line Numbers
  1. Imports System.DirectoryServices
  2. Imports System.DirectoryServices.ActiveDirectory
  3. Imports System
  4. Imports System.Collections
  5. Imports System.Collections.Specialized
  6.  
  7.  
  8. Module Module1
  9.  
  10.     Sub Main()
  11.  
  12.         Dim LDAP As String = 
  13. "LDAP://OU=Perth,DC=cnn,DC=com,DC=au" (This is an example, use your own domain e.g."LDAP://CNN".
  14.  
  15.         Dim origWidth, width As Integer
  16.         Dim origHeight, height As Integer
  17.  
  18.         origWidth = Console.WindowWidth
  19.         origHeight = Console.WindowHeight
  20.         width = origWidth * 1.5
  21.         height = origHeight * 2.5
  22.  
  23.         Console.SetWindowSize(width, height)
  24.  
  25.         Dim entry As New DirectoryEntry(LDAP, Nothing, Nothing, DirectoryServices.AuthenticationTypes.Secure)
  26.  
  27.         Dim ADSearcher As New DirectorySearcher(entry)
  28.         ADSearcher.Filter = "(&(objectCategory=person)(objectClass=user))"
  29.  
  30.         '"(objectCategory=person)"
  31.  
  32.         With ADSearcher
  33.             .SearchRoot = entry
  34.             .PropertiesToLoad.Add("telephoneNumber")
  35.             .PropertiesToLoad.Add("homeNumber")
  36.             .PropertiesToLoad.Add("mobile")
  37.             .PropertiesToLoad.Add("ipphone")
  38.             .PropertiesToLoad.Add("facsimileTelephoneNumber")
  39.             .PropertiesToLoad.Add("cn")
  40.         End With
  41.  
  42.  
  43.         Dim adColl As System.DirectoryServices.SearchResultCollection
  44.         Dim Phone, Cell, Home, IPhone, Fax, CN As System.DirectoryServices.ResultPropertyValueCollection
  45.  
  46.         Try
  47.  
  48.             adColl = ADSearcher.FindAll()
  49.  
  50.             Dim i As Integer
  51.  
  52.             For i = 0 To adColl.Count - 1
  53.                 Dim adEntry As SearchResult = adColl(i)
  54.                 Phone = adEntry.Properties("telephoneNumber")
  55.                 Home = adEntry.Properties("homeNumber")
  56.                 Cell = adEntry.Properties("mobile")
  57.                 iphone = adEntry.Properties("ipphone")
  58.                 Fax = adEntry.Properties("facsimileTelephoneNumber")
  59.                 CN = adEntry.Properties("cn")
  60.  
  61.                 Dim user As String = CN.Item(0)
  62.                 Dim phoneNumber As String = ""
  63.                 Dim homeNumber As String = ""
  64.                 Dim cellNumber As String = ""
  65.                 Dim ipphone As String = ""
  66.                 Dim Fx As String = ""
  67.  
  68.                 Try
  69.                     phoneNumber = Phone.Item(0).ToString
  70.                     homeNumber = Phone.Item(0).ToString
  71.                     cellNumber = Phone.Item(0).ToString
  72.                     ipphone = Phone.Item(0).ToString
  73.                     Fx = Phone.Item(0).ToString
  74.  
  75.                 Catch ex As Exception
  76.                     'No phone number exists.
  77.                     phoneNumber = "n/a"
  78.                     homeNumber = "n/a"
  79.                     cellNumber = "n/a"
  80.                     ipphone = "n/a"
  81.                     Fx = "n/a"
  82.                 End Try
  83.  
  84.                 Console.WriteLine(String.Format("User: {0}, Phone: {1}, Home: {2}, Cell: {3}, IPPhone: {4}, Fax: {5}", user, phoneNumber, homeNumber, cellNumber, ipphone, Fx))
  85.  
  86.             Next i
  87.             Console.ReadLine()
  88.  
  89.         Catch ex As Exception
  90.             Console.WriteLine(ex.Message.ToString)
  91.         Finally
  92.             adColl.Dispose()
  93.             ADSearcher.Dispose()
  94.             entry.Dispose()
  95.         End Try
  96.  
  97.     End Sub
  98.  
  99. End Module
____________

regards

Hems
Jul 5 '07 #1
1 2804
kenobewan
4,871 Expert 4TB
Seems strange to me that all the numbers are give the value Phone.Item(0).ToString.
Jul 5 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Victor Lokhmatov | last post by:
Hello Everyone, My company has asked me to put a company directory on our intranet site and I'm trying to use php to extract the users from our active directory server. I've got everything...
2
by: DotNetJunkies User | last post by:
Does anyone know how to get the user information such as Name, Address, Email, Phone Number, etc from Windows Active Directory? The samples I have seen so far don’t get the User Address, Email, or...
6
by: Peter | last post by:
I am trying to get values from Global Address List in Outlook through Active Directory I am able to get all the values except the 'location'. There seems to be no 'location' variable Is there...
2
by: Jim in Arizona | last post by:
My goal, somehow, is to populate a dropdownlist with all the user names in active directory. I don't even know where to begin, really. I added a reference to System.DirectoryServices so I could...
0
by: Chung Leong | last post by:
In this brief tutorial I'll describe how you retrieve information from an Active Directory through the OLE-DB extension. While it is possible to use the LDAP extension to achieve the same goal, as...
4
by: IainM | last post by:
How can I enumerate AD objects (only in a given OU, not sub OUs) using the DirectoryEntry object? Let me know of this is the wrong forum for this question. Thanks, Iain
1
by: htperth | last post by:
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...
0
by: rbukkara | last post by:
Hi, I have got the following error while trying to add a user in the LDAP Directory. javax.naming.NameNotFoundException: ; remaining name 'uid=vassila,ou=People,dc=cs,dc=uno,dc=edu' I have...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.