M
Morten Fagermoen
Hi!
I have the function below that return all users in a group, but this code
does not work if there are nested groups.
Can anyone tell me what to change to also get the users in the nested
groups?
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
If results.Properties.Contains(attributeWithRange) Then
For Each obj As Object In
results.Properties(attributeWithRange)
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
Loop While Not quitLoop
Catch ex As Exception
Console.WriteLine("Error! Could not connect to group " &
ggmGroup & ". - " & ex.ToString)
End Try
End Sub
Regards
Morten Fagermoen
I have the function below that return all users in a group, but this code
does not work if there are nested groups.
Can anyone tell me what to change to also get the users in the nested
groups?
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
If results.Properties.Contains(attributeWithRange) Then
For Each obj As Object In
results.Properties(attributeWithRange)
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
Loop While Not quitLoop
Catch ex As Exception
Console.WriteLine("Error! Could not connect to group " &
ggmGroup & ". - " & ex.ToString)
End Try
End Sub
Regards
Morten Fagermoen