Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old August 31st, 2008, 03:59 PM
Newbie
 
Join Date: Aug 2008
Posts: 1
Default Get Telephone-Number from Active Directory

I am trying to retrieve the telephone_number from active directory using the following script:

Dim search As New DirectorySearcher("")

search.Filter = "(&(objectCategory=Person)(objectClass=user)(!(use rAccountControl:1.2.840.113556.1.4.803:=2))(samacc ountname=" + UserName.ToString.Trim + "))"
'search.Filter = "(&(!(userAccountControl:1.2.840.113556.1.4.803:=2 ))( objectCategory=person)(samaccountname=" + UserName.ToString.Trim + "))"
search.PropertiesToLoad.Add("samaccountname")
search.PropertiesToLoad.Add("sn")
search.PropertiesToLoad.Add("givenname")
search.PropertiesToLoad.Add("mail")
search.PropertiesToLoad.Add("physicaldeliveryoffic ename")
search.PropertiesToLoad.Add("Telephone-Number")

Dim result As SearchResult = search.FindOne()

If Not (IsNothing(result)) Then
Try
Dim myResultPropColl As ResultPropertyCollection
myResultPropColl = result.Properties

Dim myKey As String
For Each myKey In myResultPropColl.PropertyNames
Select Case myKey
Case "samaccountname"
Try
UserName = myResultPropColl(myKey)(0)

Catch ex As Exception
UserName = ""

End Try
Case "sn"
Try
SurName = myResultPropColl(myKey)(0)

Catch ex As Exception
SurName = ""

End Try
Case "givenname"
Try
FirstName = myResultPropColl(myKey)(0)

Catch ex As Exception
FirstName = ""

End Try
Case "mail"
Try
Email = myResultPropColl(myKey)(0)

Catch ex As Exception
Email = ""

End Try
Case "Telephone-Number"
Try
Phone = myResultPropColl(myKey)(0)

Catch ex As Exception
Phone = ""

End Try
Case "physicaldeliveryofficename"
Try
Office = myResultPropColl(myKey)(0)

Catch ex As Exception
Office = ""
End Try
End Select
Next
If Email <> "" Then
DatatoWrite = InUserName & "|" & UserName & "|" & SurName & "|" & FirstName & "|" & Email & "|" & Phone & "|" & newnumber & "|" & Office & "|" & newoffice
End If

Catch ex As Exception
errcount = errcount + 1
DatatoWrite = InUserName & "| UserID Not Found "
End Try
Else
errcount = errcount + 1
DatatoWrite = InUserName & "| UserID Not Found "

End If

I get all the data EXCEPT Telephone-Number

UserName if provided via an input file

Any help will be greatly appreciated
Reply
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles