getting list of users from AD

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Henry

    getting list of users from AD

    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)


  • Stanley

    #2
    Re: getting list of users from AD

    Public Function ListADUsers()

    Try

    Dim dsUsers As New DataSet

    Dim entry As New DirectoryServic es.DirectoryEnt ry("")

    Dim mySearcher As New System.Director yServices.Direc torySearcher(en try)

    Dim result As System.Director yServices.Searc hResult

    dsUsers.Tables. Add()

    dsUsers.Tables( 0).Columns.Add( New DataColumn("use rname"))

    dsUsers.Tables( 0).Columns.Add( New DataColumn("ful lname"))

    dsUsers.Tables( 0).Columns.Add( New DataColumn("tit le"))

    dsUsers.Tables( 0).Columns.Add( New DataColumn("mai l"))

    dsUsers.Tables( 0).Columns.Add( New DataColumn("gro ups"))

    'sets the filter for all user accounts

    'mySearcher.Fil ter = "(objectClass=U ser)"

    mySearcher.Filt er =
    "(&(objectCateg ory=person)(obj ectClass=user)( !userAccountCon trol:1.2.840.11 3
    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.Find All()

    'Dim propcoll As ResultPropertyC ollection = result.Properti es

    Dim u As New oUser(result)

    Dim fullname As String = u.AccountName

    Dim row As DataRow

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

    Or InStr(fullname, "{", CompareMethod.B inary) _

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

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

    Or InStr(1, LCase(fullname) , "account", CompareMethod.B inary) 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.Acco untName)

    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.t xt")

    sw.Write(ex.Mes sage & vbCrLf & vbCrLf & ex.StackTrace)

    sw.Close()

    sw = Nothing

    End Try

    End Function

    "Brian Henry" <brianiup@adelp hia.net> wrote in message
    news:e%23SI3Tab DHA.3896@TK2MSF TNGP11.phx.gbl. ..[color=blue]
    > 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...[/color]
    is[color=blue]
    > this possible to get a list of user names from ad? (the server is on the
    > domain that hosts the intranet site)
    >
    >[/color]


    Comment

    • Brian Henry

      #3
      Re: getting list of users from AD

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

      --
      =============== =============== ==
      Brian Henry
      The Reschini Group


      "Stanley" <sglass@jsaheal thcare.com> wrote in message
      news:%2386tNEkb DHA.2344@TK2MSF TNGP09.phx.gbl. ..[color=blue]
      > Public Function ListADUsers()
      >
      > Try
      >
      > Dim dsUsers As New DataSet
      >
      > Dim entry As New DirectoryServic es.DirectoryEnt ry("")
      >
      > Dim mySearcher As New System.Director yServices.Direc torySearcher(en try)
      >
      > Dim result As System.Director yServices.Searc hResult
      >
      > dsUsers.Tables. Add()
      >
      > dsUsers.Tables( 0).Columns.Add( New DataColumn("use rname"))
      >
      > dsUsers.Tables( 0).Columns.Add( New DataColumn("ful lname"))
      >
      > dsUsers.Tables( 0).Columns.Add( New DataColumn("tit le"))
      >
      > dsUsers.Tables( 0).Columns.Add( New DataColumn("mai l"))
      >
      > dsUsers.Tables( 0).Columns.Add( New DataColumn("gro ups"))
      >
      > 'sets the filter for all user accounts
      >
      > 'mySearcher.Fil ter = "(objectClass=U ser)"
      >
      > mySearcher.Filt er =
      >[/color]
      "(&(objectCateg ory=person)(obj ectClass=user)( !userAccountCon trol:1.2.840.11 3[color=blue]
      > 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.Find All()
      >
      > 'Dim propcoll As ResultPropertyC ollection = result.Properti es
      >
      > Dim u As New oUser(result)
      >
      > Dim fullname As String = u.AccountName
      >
      > Dim row As DataRow
      >
      > If InStr(1, fullname, "$", CompareMethod.B inary) Or fullname = "" _
      >
      > Or InStr(fullname, "{", CompareMethod.B inary) _
      >
      > Or InStr(1, fullname, "NAV ", CompareMethod.B inary) _
      >
      > Or InStr(1, fullname, "mail ", CompareMethod.B inary) _
      >
      > Or InStr(1, LCase(fullname) , "account", CompareMethod.B inary) 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.Acco untName)
      >
      > 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.t xt")
      >
      > sw.Write(ex.Mes sage & vbCrLf & vbCrLf & ex.StackTrace)
      >
      > sw.Close()
      >
      > sw = Nothing
      >
      > End Try
      >
      > End Function
      >
      > "Brian Henry" <brianiup@adelp hia.net> wrote in message
      > news:e%23SI3Tab DHA.3896@TK2MSF TNGP11.phx.gbl. ..[color=green]
      > > I am working on a internal intranet site, and i need to make a[/color][/color]
      permissions[color=blue][color=green]
      > > page, all the account authorization is done through AD to let them see[/color][/color]
      the[color=blue][color=green]
      > > intranet site.. now, the permissions page i need a list of users in[/color][/color]
      AD...[color=blue]
      > is[color=green]
      > > this possible to get a list of user names from ad? (the server is on the
      > > domain that hosts the intranet site)
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...