Solved

AD connection get mail properties problem

Posted on 2011-03-08
7
751 Views
Last Modified: 2012-05-11
Hi,

VB, VS 2010express,

Im trying to get email properties from AD, when I do

 Public Shared Sub ADconnection()

        Dim oSearcher As New DirectorySearcher
        Dim oResults As SearchResultCollection
        Dim oResult As SearchResult
        Dim mCount As Integer
        Dim mLDAPRecord, mLDAPemail, mLDAPFullname As String

        Dim ResultFields() As String = {"securityEquals", "cn"}

        Try
            With oSearcher
                .SearchRoot = New DirectoryEntry("LDAP://" & "domainserver" & _
          "/dc=xxx,dc=local")
                .PropertiesToLoad.AddRange(ResultFields)
                .Filter = "sn=" & "*"
                oResults = .FindAll()
            End With

            mCount = oResults.Count
            If mCount > 0 Then
                For Each oResult In oResults
                    mLDAPRecord = oResult.GetDirectoryEntry().Properties("cn").Value
                    mLDAPemail = oResult.GetDirectoryEntry().Properties("mail").Value
                    mLDAPFullname = oResult.GetDirectoryEntry().Properties("sn").Value
                   
                Next
            End If
        Catch e As Exception

            MsgBox("Error is " & e.Message)

        End Try

    End Sub

Open in new window



then everything is working but if I change filter="cn=username" then even if he find a record it's not taking email address
any reason why?

thanks for all advise
regards
0
Comment
Question by:gowerman
  • 4
  • 3
7 Comments
 
LVL 11

Expert Comment

by:Tasmant
ID: 35067918
could it not be possible that your recordset don't contain the expected property?
Dim ResultFields() As String = {"securityEquals", "cn"}
I would change it to:
Dim ResultFields() As String = {"securityEquals", "cn", "mail"}
and maybe more to:
Dim ResultFields() As String = {"securityEquals", "cn", "mail", "sn"}

0
 

Author Comment

by:gowerman
ID: 35068274
i change as you said but still same. I checked several records they all contain that property as when I run the first one it takes all users emails
0
 
LVL 11

Expert Comment

by:Tasmant
ID: 35068368
this attribute shouldn't be a multivalued attribute, but i've found some code
mLDAPemail = oResult.GetDirectoryEntry().Properties("mail")(0).toString()
mLDAPemail = oResult.GetDirectoryEntry().Properties("mail")(0).Value
maybe can you try ...
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 

Author Comment

by:gowerman
ID: 35068810
when I tried this then I have index is out of range
0
 
LVL 11

Expert Comment

by:Tasmant
ID: 35068874
ok so this is singlevalued, that's fine. Don't know why you encounter the issue, i'll try to investigate further.
0
 

Accepted Solution

by:
gowerman earned 0 total points
ID: 35892591
I search by samaccount and that is working now
0
 

Author Closing Comment

by:gowerman
ID: 35913771
thats works for me
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This article runs through the process of deploying a single EXE application selectively to a group of user.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question