Active directory groups are not listed for a user (at times ) using LDAP

Last post 03-23-2007 1:54 AM by radhuvas. 0 replies.

Sort Posts:

  • Active directory groups are not listed for a user (at times ) using LDAP

    03-23-2007, 1:54 AM
    • Loading...
    • radhuvas
    • Joined on 03-23-2007, 1:41 AM
    • Posts 1

    Hi All,

    I am using LDAP to get active directroy groups for a given user.

     I am able to see the AD gorups list some times. But it is not consistent.

     Some times I get empty list. If any one can help in this regard, It would be great. If you have any other way of getting AD groups Please let me know.

     This is the code I am using

    Public Shared Function GetADUserGroups(ByVal UserName As String) As String

    Dim grouplist As New StringBuilder()

    Dim result As SearchResult

    Dim groupcount As Integer = 0

    Dim counter As Integer = 0

    Dim pos As Integer

    Dim search As New DirectorySearcher()

    search.Filter =

    "sAMAccountName=" & UserName

    Dim ADList As New StringBuilder()

    search.PropertiesToLoad.Add(

    "MemberOf")

    result = search.FindOne

    If Not IsNothing(result) Then

    groupcount = result.Properties(

    "memberOf").Count  '- AD group Count is correct always.

    For counter = 0 To groupcount - 1

    ADList.Append(result.Properties.Item(

    "memberOf")(counter).ToString()) '- This shows empty at times

    If ADList.Length > 0 Then

    grouplist.Append(

    "'" + ADList.ToString + "'")  ' Creating a comma seperated list with AD Group details

    If counter < groupcount - 1 Then

    grouplist.Append(

    ",")

    End If

    ADList.Remove(0, ADList.Length)

    End If

    End If

     

    Next

    End If

    Thanks in Advance

    Regards

    Radha

    Dim k As New System.IO.StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "/grouplist.txt")

    k.Write(grouplist.ToString())

     

    k.Close()

     

    Return grouplist.ToString()

    End Function
Page 1 of 1 (1 items)
Microsoft Communities
Page view counter