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: -
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.ResultPropertyValueCollection
-
-
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
1 2804
Seems strange to me that all the numbers are give the value Phone.Item(0).ToString.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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
| |