Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

AD connection get mail properties problem

Posted on 2011-03-08
7
Medium Priority
?
758 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
Wouldn't it be nice if objects in Active Directory automatically moved into the correct Organizational Units? This is what AutoAD aims to do and as a plus, it automatically creates Sites, Subnets, and Organizational Units.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

722 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