getting list of users from AD

  • Thread starter Thread starter Brian Henry
  • Start date Start date
B

Brian Henry

I am working on a internal intranet site, and i need to make a permissions
page, all the account authorization is done through AD to let them see the
intranet site.. now, the permissions page i need a list of users in AD... is
this possible to get a list of user names from ad? (the server is on the
domain that hosts the intranet site)
 
Public Function ListADUsers()

Try

Dim dsUsers As New DataSet

Dim entry As New DirectoryServices.DirectoryEntry("")

Dim mySearcher As New System.DirectoryServices.DirectorySearcher(entry)

Dim result As System.DirectoryServices.SearchResult

dsUsers.Tables.Add()

dsUsers.Tables(0).Columns.Add(New DataColumn("username"))

dsUsers.Tables(0).Columns.Add(New DataColumn("fullname"))

dsUsers.Tables(0).Columns.Add(New DataColumn("title"))

dsUsers.Tables(0).Columns.Add(New DataColumn("mail"))

dsUsers.Tables(0).Columns.Add(New DataColumn("groups"))

'sets the filter for all user accounts

'mySearcher.Filter = "(objectClass=User)"

mySearcher.Filter =
"(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113
556.1.4.803:=2))"

'loop through the results and print out the name and displayname

Dim i As Integer = 0

For Each result In mySearcher.FindAll()

'Dim propcoll As ResultPropertyCollection = result.Properties

Dim u As New oUser(result)

Dim fullname As String = u.AccountName

Dim row As DataRow

If InStr(1, fullname, "$", CompareMethod.Binary) Or fullname = "" _

Or InStr(fullname, "{", CompareMethod.Binary) _

Or InStr(1, fullname, "NAV ", CompareMethod.Binary) _

Or InStr(1, fullname, "mail ", CompareMethod.Binary) _

Or InStr(1, LCase(fullname), "account", CompareMethod.Binary) Then

Else

row = dsUsers.Tables(0).NewRow

row("username") = u.AccountName

row("fullname") = u.DisplayName

row("title") = u.Title

row("mail") = u.Email

Dim j As Integer = 0

Dim _Groups As String = u.Groups(u.AccountName)

row("groups") = _Groups

dsUsers.Tables(0).Rows.Add(row)

End If

Next

If dsUsers.Tables(0).Rows.Count < 1 Then

Throw New Exception("No users returned")

End If

Return dsUsers

Catch ex As Exception

Dim sw As New IO.StreamWriter("c:\ws_error.txt")

sw.Write(ex.Message & vbCrLf & vbCrLf & ex.StackTrace)

sw.Close()

sw = Nothing

End Try

End Function
 
your variable oUser is undeclared, thus makeing this useless till you know
what type the var oUser is.. thanks
 
Back
Top