编写需要显示Active Directory动态通讯组列表的vb.net应用程序。下面的代码在检索组列表时起作用 - 但在将OU = DynamicDistributionGroups添加到上下文定义时,不返回任何内容。可以使用GroupPrincipal以这种方式获取动态通讯组吗?建议欢迎?感谢
Using ctx As New PrincipalContext
(ContextType.Domain, "MYLAN", "OU=DynamicDistributionGroups,OU=Email
Groups,DC=mylan,DC=ac,DC=mycompany,DC=com")
Dim pGroup As New GroupPrincipal(ctx)
pGroup.Name = "*"
Dim pSearcher As New PrincipalSearcher()
pSearcher.QueryFilter = pGroup
Dim results As PrincipalSearchResult(Of Principal) = pSearcher.FindAll()
For Each p As Principal In results
listGroup.Items.Add(p.ToString())
Next
End Using
答案 0 :(得分:0)
我能够使用DirectorySearcher而不是Principal Context完成此任务,如下所示:
Dim results As SearchResultCollection
Dim srch As New DirectorySearcher("LDAP://MYLAN/OU=DynamicDistributionGroups,OU=Email
Groups,DC=mylan,DC=ac,DC=mycompany,DC=com")
srch.Filter = "(objectClass=msExchDynamicDistributionList)"
srch.PropertiesToLoad.Add("displayName")
srch.PageSize = 1000
results = srch.FindAll()
For Each result As SearchResult In results
Dim props As ResultPropertyCollection = result.Properties
For Each propName As String In props.PropertyNames
Dim groupName As String = props(propName)(0)
Next
Next