Get User Email Address in Active Directory in

Good morning all and hope you had a great weekend! This weekend was somewhat comical for me. First I had gotten a basketball hoop and backboard and on Saturday decided it was time to put it together. The box said "Some Assembly Required". Alrighty then shouldn’t be a problem right? I started at about 9am and finished it at……approximately 5PM. Granted I took breaks to do other stuff but it was frustrating to put together. But granted it was all worthwhile because my daughter Alyssa came out and shot "horse" with me on Sunday night. And that is always fun for me. Plus I get her off the couch, away from the computer and the TV which is a bonus!

Then on Sunday, I went to pick up my exercise machine. It didn’t fit exactly into the truck very well so I sat in back making sure it didn’t go anywhere while my wife drove us home. When we get there it was time to remove it but it wouldn’t come out! What’s worse is as it was coming out one of the handles started to poke a hole in the roof of the truck (It’s an Explorer). So I went to get a neighbor whom I have never met before and the three of us managed to get it out. Unfortunately this thing on one side weighed about 200 lbs and I was on this side going down the stairs to my basement. As I was going I felt this stretching, piercing kind of pain in my lower back. This morning which was to begin my workout routine I am pretty hunched over.

The good news is we met a neighbor, a rather nice guy I might add, which we probably would not have before. So something good came out of that effort too.

Anyway today’s topic. Nothing exciting. All I am doing is getting the users email address from Active Directory. I am writing this as part of an application to send out reports to various people. Anyway, make it a great day!

Join me on Facebook

Public Function GetCurUserEmail(ByVal DomainObj As ActiveDs.IADsContainer, ByVal TargetUserID As String) As String
            Dim User As ActiveDs.IADsUser
            Dim EmailAddress As String = ""
                If Not DomainObj Is Nothing Then
                    DomainObj.Filter = New Object() {"User"}
                    For Each User In DomainObj
                        Dim UserName As String
                        UserName = Replace(User.Name, "CN=", "")
                        If TargetUserID = UserName Then
                            EmailAddress = User.EmailAddress
                            Exit For
                        End If
                    User = Nothing
                    DomainObj = Nothing
                    Return EmailAddress
                    Return Nothing
                End If
            Catch e As Exception
                Return Nothing
            End Try
        End Function



  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: