Hi! I have a function that returns a System.Collecti ons.Generic.Lis t(Of
String) of the users in a specified group.
It seems to work fine with an exception of the Domain Users group. When I
query Domain Users I only get a few users back even if it is several
thousand members in this group.
The code I use is:
Sub GetGroupMembers (ByVal ggmGroup As String, ByRef ggmMembers As
System.Collecti ons.Generic.Lis t(Of String))
Try
Dim entry As DirectoryEntry = New DirectoryEntry( ggmGroup)
Dim searcher As DirectorySearch er = New DirectorySearch er(entry)
searcher.Filter = "(objectClass=* )"
Dim rangeStep As System.UInt32 = 1000
Dim rangeLow As System.UInt32 = 0
Dim rangeHigh As System.UInt32 = CUInt(rangeLow + (rangeStep -
1))
Dim lastQuery As Boolean = False
Dim quitLoop As Boolean = False
Do
Dim attributeWithRa nge As String
If Not lastQuery Then
attributeWithRa nge =
String.Format(" member;range={0 }-{1}", rangeLow, rangeHigh)
Else
attributeWithRa nge = String.Format(" member;range={0 }-*",
rangeLow)
quitLoop = True
End If
searcher.Proper tiesToLoad.Clea r()
searcher.Proper tiesToLoad.Add( attributeWithRa nge)
Dim results As SearchResult = searcher.FindOn e
For Each res As String In results.Propert ies.PropertyNam es
System.Diagnost ics.Debug.Write Line(res.ToStri ng)
Next
If results.Propert ies.Contains(at tributeWithRang e) Then
For Each obj As Object In
results.Propert ies(attributeWi thRange)
If obj.GetType.Equ als(GetType(Sys tem.String)) Then
Else
If obj.GetType.Equ als(GetType(Sys tem.Int32))
Then
End If
End If
ggmMembers.Add( obj.ToString)
Next
Else
lastQuery = True
End If
If Not lastQuery Then
rangeLow = CUInt(rangeHigh + 1)
rangeHigh = CUInt(rangeLow + (rangeStep - 1))
End If
attributeWithRa nge = Nothing
results = Nothing
Loop While Not quitLoop
entry = Nothing
searcher = Nothing
rangeStep = Nothing
rangeLow = Nothing
rangeHigh = Nothing
lastQuery = Nothing
quitLoop = Nothing
Catch ex As Exception
logfile.WriteLi ne("Error! Could not connect to group " &
ggmGroup & ". - " & ex.ToString)
End Try
End Sub
Can anyone tell me what is wrong?
Regads
Morten Fagermoen
String) of the users in a specified group.
It seems to work fine with an exception of the Domain Users group. When I
query Domain Users I only get a few users back even if it is several
thousand members in this group.
The code I use is:
Sub GetGroupMembers (ByVal ggmGroup As String, ByRef ggmMembers As
System.Collecti ons.Generic.Lis t(Of String))
Try
Dim entry As DirectoryEntry = New DirectoryEntry( ggmGroup)
Dim searcher As DirectorySearch er = New DirectorySearch er(entry)
searcher.Filter = "(objectClass=* )"
Dim rangeStep As System.UInt32 = 1000
Dim rangeLow As System.UInt32 = 0
Dim rangeHigh As System.UInt32 = CUInt(rangeLow + (rangeStep -
1))
Dim lastQuery As Boolean = False
Dim quitLoop As Boolean = False
Do
Dim attributeWithRa nge As String
If Not lastQuery Then
attributeWithRa nge =
String.Format(" member;range={0 }-{1}", rangeLow, rangeHigh)
Else
attributeWithRa nge = String.Format(" member;range={0 }-*",
rangeLow)
quitLoop = True
End If
searcher.Proper tiesToLoad.Clea r()
searcher.Proper tiesToLoad.Add( attributeWithRa nge)
Dim results As SearchResult = searcher.FindOn e
For Each res As String In results.Propert ies.PropertyNam es
System.Diagnost ics.Debug.Write Line(res.ToStri ng)
Next
If results.Propert ies.Contains(at tributeWithRang e) Then
For Each obj As Object In
results.Propert ies(attributeWi thRange)
If obj.GetType.Equ als(GetType(Sys tem.String)) Then
Else
If obj.GetType.Equ als(GetType(Sys tem.Int32))
Then
End If
End If
ggmMembers.Add( obj.ToString)
Next
Else
lastQuery = True
End If
If Not lastQuery Then
rangeLow = CUInt(rangeHigh + 1)
rangeHigh = CUInt(rangeLow + (rangeStep - 1))
End If
attributeWithRa nge = Nothing
results = Nothing
Loop While Not quitLoop
entry = Nothing
searcher = Nothing
rangeStep = Nothing
rangeLow = Nothing
rangeHigh = Nothing
lastQuery = Nothing
quitLoop = Nothing
Catch ex As Exception
logfile.WriteLi ne("Error! Could not connect to group " &
ggmGroup & ". - " & ex.ToString)
End Try
End Sub
Can anyone tell me what is wrong?
Regads
Morten Fagermoen