我正在查询组中所有成员的 AD。
结果,我得到了用户和组。我的问题:我怎样才能知道,单一的结果是什么(个人或团体)?
这是我的代码,我得到一个 Resultpropertycollection,当我遍历集合时,我想知道每个项目是一个人还是一个组。
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
问候亚武兹
更新:
这是完整的代码:
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