如何使用PrincipalContext获取Active Directory动态通讯组? [英] How do I get Active Directory Dynamic Distribution Groups using PrincipalContext?

查看:88
本文介绍了如何使用PrincipalContext获取Active Directory动态通讯组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写需要显示Active Directory动态通讯组列表的vb.net应用程序。下面的代码在检索组列表时起作用 - 但在将OU = DynamicDistributionGroups添加到上下文定义时,不返回任何内容。可以使用GroupPrincipal以这种方式获取动态通讯组吗?建议欢迎?谢谢



 使用 ctx 作为  PrincipalContext 
(ContextType.Domain, MYLAN OU = DynamicDistributionGroups,OU =电子邮件群组,DC = mylan ,DC = ac,DC = mycompany,DC = com

Dim pGroup 作为 GroupPrincipal(ctx)
pGroup.Name = < span class =code-string> *
Dim pSearcher As PrincipalSearcher()
pSearcher.QueryFilter = pGroup
Dim 结果作为 PrincipalSearchResult( Of Principal)= pSearcher.FindAll()
对于 每个 p 作为 Principal 结果
listGroup.Items.Add(p.ToString())
下一步
结束 使用

解决方案

您应首先尝试获取包括动态通讯组在内的所有组。我相信(没有可能在这里测试)你需要从你的定义中删除两个OU。



然后,你可以检查每个组是否是一个SecurityGroup。如果没有,它是一个动态通讯组...

 使用 ctx 作为  PrincipalContext 
(ContextType.Domain, MYLAN DC = mylan,DC = ac,DC = mycompany,DC = com

Dim pGroup As GroupPrincipal(ctx)
pGroup.Name = *
Dim pSearcher As PrincipalSearcher()
pSearcher.QueryFilter = pGroup
Dim 结果作为 PrincipalSearchResult( Of Principal)= pSearcher.FindAll()
对于 每个 p As Principal 结果
Dim gp 作为 GroupPrincipal = p
如果 gp .IsSecurityGroup 然后 listGroup.Items.Add(p.ToString())
下一步
结束 使用



免责声明:未经测试代码,没有VS,没有AD ...


感谢您提出的解决方案。然而,我能够使用DirectorySearcher而不是PrincipalContext完成任务,如下所示:



  Dim 结果 As  SearchResultCollection 
Dim srch 作为 DirectorySearcher( LDAP :// MYLAN / OU = DynamicDistributionGroups,OU =电子邮件组,DC = mylan,DC = ac,DC = mycmpany,DC = com
srch.Filter = (objectClass = msExchDynamicDistributionList)
srch.PropertiesToLoad.Add( displayName
srch.PageSize = 1000
results = srch .FindAll()
对于 每个结果正如 SearchResult 结果中
Dim props 作为 ResultPropertyCollection = result.Properties
对于 每个 propName 作为 字符串 props.PropertyNames
< span class =code-keyword> Dim groupName As String = props(propName) ( 0
下一步
下一步


Writing a vb.net application that needs to display a list of Active Directory Dynamic Distribution Groups. The code below works when retrieving a list of groups - but returns nothing when I add the OU=DynamicDistributionGroups to the context definition. Can Dynamic Distribution Groups be obtained using the GroupPrincipal this way? Suggestions are welcome? Thanks

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

解决方案

You should first try to get all groups including the Dynamic Distribution Groups. I believe (without having the possibility to test it here) that you need to remove both OU's from your definition.

Then, you can check for each group if it's a SecurityGroup. If not, it's a Dynamic Distribution Group...

Using ctx As New PrincipalContext 
  (ContextType.Domain, "MYLAN", "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
       Dim gp As GroupPrincipal = p
       If Not gp.IsSecurityGroup Then listGroup.Items.Add(p.ToString())
   Next
End Using


Disclaimer: untested code, no VS and no AD here...


Thanks for the proposed solution. I was however able to accomplish the task using DirectorySearcher rather than PrincipalContext as follows:

Dim results As SearchResultCollection
Dim srch As New DirectorySearcher("LDAP://MYLAN/OU=DynamicDistributionGroups,OU=Email Groups,DC=mylan,DC=ac,DC=mycmpany,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


这篇关于如何使用PrincipalContext获取Active Directory动态通讯组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆