468,167 Members | 1,909 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,167 developers. It's quick & easy.

Get Telephone-Number from Active Directory

1
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
Aug 31 '08 #1
0 2583

Post your reply

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

Similar topics

reply views Thread by Cesare Nicolai C. | last post: by
reply views Thread by Ike | last post: by
reply views Thread by BizTalk Architect | last post: by
reply views Thread by Mark | last post: by
reply views Thread by Don Quijote de Nicaragua | last post: by
1 post views Thread by Ed Dror | last post: by
3 posts views Thread by Smythe32 | last post: by
1 post views Thread by gcdp | last post: by
reply views Thread by kamranasdasdas | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.