Query Exchange/Active Directory for Distribution Lists with vb.net

Good Morning all. I did not have a good night. My eldest daughter who is 17 gave us considerable problems. Someday I will go into that in a future blog entry. Just so much to say about it and more than most of you want to know I am sure.

Anyway we want to query Exchange or Active Directory for Distribution Lists. My purpose was to make sure a particular report got to everyone.

Make it a great day!

Private Sub LoadUserGroupTable(Optional ByVal _SortField As String = "user_name")
            ‘ bind the data to the datagrid
            Dim clsApp As New CustomAppSettings
            Dim de As New DirectoryEntry( _
                AppSettings("ActiveDirectoryPath"), _
                clsApp.GetAppSetting("ADUsername"), _
                clsApp.GetAppSetting("ADPassword"))
            Dim src As New DirectorySearcher
            With src
                .Filter = "(&(objectcategory=Person)(|(objectclass=User)(cn=Network Distribution Lists)))"
                .SearchRoot = de
                .SearchScope = SearchScope.Subtree
            End With
            Dim res As SearchResult
            CreateUserGroupTable()
            For Each res In src.FindAll
                Try
                    Dim topRow As DataRow = UserGroupTable.NewRow
                    topRow("user_name") = res.Properties("displayname")(0).ToString
                    topRow("username") = res.Properties("displayname")(0).ToString
                    topRow("email") = res.Properties("mail")(0).ToString
                    UserGroupTable.Rows.Add(topRow)
                Catch ex As Exception
                    ‘ do nothing
                    ‘Dim clsErr As New ABCNetErrors
                    ‘clsErr.NotifyABCNetAdmin("Could not bind Group to a DataRow", ex)
                End Try
            Next
            Dim dv As DataView = New DataView(UsersTable)
            dv.Sort = "user_name ASC"
            With lbGroups
                .DataSource = dv
                .DataTextField = "user_name"
                .DataValueField = "email"
                .DataBind()
            End With
        End Sub

 

Advertisements
  1. Leave a comment

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: