i am querying the AD for all members of a group.
As a result i get users AND groups. My question: How can i find out, what the single result is (person or group)?
This is my code, i get a Resultpropertycollection and when i loop through the collection, i want to know for each item if it is a person or group.
ds.PropertiesToLoad.Add("member")
For Each sr As SearchResult In ds.FindAll
Dim valueCollection As ResultPropertyValueCollection = sr.Properties("member")
Dim propertyValue As Object
For Each propertyValue In valueCollection
Console.WriteLine("{0}", propertyValue.ToString())
Next propertyValue
Next
regards Yavuz
Update:
This is th full code:
Private Sub EnumPropertyAndMembersOfGroup(ByVal name As String, ByVal propertyname As String)
Try
Dim de As DirectoryEntry = New DirectoryEntry("LDAP://lab.com")
Dim ds As DirectorySearcher = New DirectorySearcher
ds.Filter = "(&(objectCategory=group)(cn=" & name & "))"
ds.PropertiesToLoad.Add("sAMAccountName")
ds.PropertiesToLoad.Add("memberOf")
ds.PropertiesToLoad.Add("member")
For Each sr As SearchResult In ds.FindAll
Console.WriteLine("Search properties for {0}", sr.Path)
Console.WriteLine()
Dim valueCollection As ResultPropertyValueCollection = sr.Properties(propertyname)
Dim propertyValue As Object
For Each propertyValue In valueCollection
Console.WriteLine("{0}", propertyValue.ToString())
Next propertyValue
Next
Console.ReadKey()
Catch ex As Exception
Console.WriteLine("ERROR: " & ex.Message)
Console.ReadKey()
End Try
End Sub