Solved

AD connection get mail properties problem

Posted on 2011-03-08
7
752 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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