title: I want to retrieve a person phone number using Active directory
body: <p>When I try to get the phone number of a person from Active Directory, all the properties are loaded but except mail nothing is returned. Can someone please help out in how to retrieve the phone number with some changes in the below code? In <code>myrelustpropcollection.propertynames</code> only 2 is the count ADSPATH and mail. No other property is loaded.</p>
  
  <pre><code>Public Function GetPhoneByName(ByVal Name As String) As String
      Dim srch As DirectorySearcher
      Dim results As SearchResultCollection = Nothing
      Dim phone As Integer
      srch = New DirectorySearcher(New DirectoryEntry())
      srch.Filter = "(mailnickname=" + Name + ")"
  
      srch.PropertiesToLoad.Add("homephone")
      srch.PropertiesToLoad.Add("mail")
      srch.PropertiesToLoad.Add("mobile")
      srch.PropertiesToLoad.Add("telephoneNumber")
  
      Try
          results = srch.FindAll()
      Catch ex As Exception
      End Try
  
      For Each result In results
          Dim myKey As String
          Dim myResultPropCollection As ResultPropertyCollection
  
          myResultPropCollection = result.Properties
  
          For Each myKey In myResultPropCollection.PropertyNames
              Dim tab1 As String = "    "
              Dim myCollection As Object
              Select Case myKey
                  Case "mobile" ' Telephone Number
                      For Each myCollection In myResultPropCollection(myKey)
                          phone = myCollection.toint
                      Next myCollection
              End Select
          Next myKey
      Next
      Return phone
  End Function
  </code></pre>