Active directory LDAP获取Active Directory中用户的主组名

Active directory LDAP获取Active Directory中用户的主组名,active-directory,ldap,ldap-query,dsquery,Active Directory,Ldap,Ldap Query,Dsquery,在一个场景中,我需要使用LDAP查询获取特定用户所属的所有组名。 输入将是:用户可分辨名称 输出应该是:此用户所属的组的列表 到目前为止,我能够使用以下LDAP查询获取用户所属的所有组名,但主组除外: dsquery * "cn=user1,cn=Users,dc=example,dc=com" -scope base -attr primaryGroupID 查询: dsquery * "member:LDAP_MATCHING_RULE_IN_CHAIN:=cn=user1,cn=User

在一个场景中,我需要使用LDAP查询获取特定用户所属的所有组名。 输入将是:用户可分辨名称 输出应该是:此用户所属的组的列表

到目前为止,我能够使用以下LDAP查询获取用户所属的所有组名,但主组除外:

dsquery * "cn=user1,cn=Users,dc=example,dc=com" -scope base -attr primaryGroupID
查询:

dsquery * "member:LDAP_MATCHING_RULE_IN_CHAIN:=cn=user1,cn=Users,dc=example,dc=com"
输出:

"CN=group1,CN=Users,DC=example,DC=com"
"CN=mygroup,CN=Users,DC=example,DC=com"
上面的查询列出了除主组名“域管理员”之外的所有组“user1”都是的成员

一些人知道如何使用下面的LDAP查询获取主组RID:

dsquery * "cn=user1,cn=Users,dc=example,dc=com" -scope base -attr primaryGroupID
但是,从group RID获取组名同样不起作用,相反,如果我获得了主组SID,那么就很容易获得组名。但我得到的是主组RID,我无法使用LDAP从中获取组名

关于这方面的任何帮助都将非常好,我可以通过任何方式仅使用一些LDAP查询来获取主组名。

您想使用dsget而不是dsquery。这是如何查找特定成员的所有组,包括嵌套组和主组:

dsget user "cn=user1,cn=Users,dc=example,dc=com" -memberof -expand
请将标签添加到此问题。