Hi! I have a function that returns a System.Collections.Generic.List(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.Collections.Generic.List(Of String))
Try
Dim entry As DirectoryEntry = New DirectoryEntry(ggmGroup)
Dim searcher As DirectorySearcher = New DirectorySearcher(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 attributeWithRange As String
If Not lastQuery Then
attributeWithRange =
String.Format("member;range={0}-{1}", rangeLow, rangeHigh)
Else
attributeWithRange = String.Format("member;range={0}-*",
rangeLow)
quitLoop = True
End If
searcher.PropertiesToLoad.Clear()
searcher.PropertiesToLoad.Add(attributeWithRange)
Dim results As SearchResult = searcher.FindOne
For Each res As String In results.Properties.PropertyNames
System.Diagnostics.Debug.WriteLine(res.ToString)
Next
If results.Properties.Contains(attributeWithRange) Then
For Each obj As Object In
results.Properties(attributeWithRange)
If obj.GetType.Equals(GetType(System.String)) Then
Else
If obj.GetType.Equals(GetType(System.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
attributeWithRange = 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.WriteLine("Error! Could not connect to group " &
ggmGroup & ". - " & ex.ToString)
End Try
End Sub
Can anyone tell me what is wrong?
Regads
Morten Fagermoen