• <tfoot id='iPDSR'></tfoot>
      <bdo id='iPDSR'></bdo><ul id='iPDSR'></ul>
    1. <small id='iPDSR'></small><noframes id='iPDSR'>

        <legend id='iPDSR'><style id='iPDSR'><dir id='iPDSR'><q id='iPDSR'></q></dir></style></legend>
      1. <i id='iPDSR'><tr id='iPDSR'><dt id='iPDSR'><q id='iPDSR'><span id='iPDSR'><b id='iPDSR'><form id='iPDSR'><ins id='iPDSR'></ins><ul id='iPDSR'></ul><sub id='iPDSR'></sub></form><legend id='iPDSR'></legend><bdo id='iPDSR'><pre id='iPDSR'><center id='iPDSR'></center></pre></bdo></b><th id='iPDSR'></th></span></q></dt></tr></i><div id='iPDSR'><tfoot id='iPDSR'></tfoot><dl id='iPDSR'><fieldset id='iPDSR'></fieldset></dl></div>
      2. ldap3 python 搜索组成员并检索他们的 sAMAcountName (Active Directory)

        时间:2023-07-24
      3. <legend id='letXo'><style id='letXo'><dir id='letXo'><q id='letXo'></q></dir></style></legend>
          <bdo id='letXo'></bdo><ul id='letXo'></ul>

          • <tfoot id='letXo'></tfoot>
            • <i id='letXo'><tr id='letXo'><dt id='letXo'><q id='letXo'><span id='letXo'><b id='letXo'><form id='letXo'><ins id='letXo'></ins><ul id='letXo'></ul><sub id='letXo'></sub></form><legend id='letXo'></legend><bdo id='letXo'><pre id='letXo'><center id='letXo'></center></pre></bdo></b><th id='letXo'></th></span></q></dt></tr></i><div id='letXo'><tfoot id='letXo'></tfoot><dl id='letXo'><fieldset id='letXo'></fieldset></dl></div>
                <tbody id='letXo'></tbody>

                1. <small id='letXo'></small><noframes id='letXo'>

                  本文介绍了ldap3 python 搜索组成员并检索他们的 sAMAcountName (Active Directory)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试将 ldap3 与 python 一起使用来检索组的成员并检索他们的 sAMAccountName,因为我们混合了 DN(一些带有 NTID,其他带有名字/姓氏).

                  I'm trying to use ldap3 with python to retrieve members of a group and also retrieve their sAMAccountName as we have mixed DN's (some with NTID and others with first/last name).

                  我一直在尝试这个没有 0 运气,任何帮助将不胜感激:

                  I've been trying this with no 0 luck, any help would be appreciated:

                  from ldap3 import Server, Connection, AUTO_BIND_NO_TLS, SUBTREE, BASE,
                        ALL_ATTRIBUTES, ObjectDef, AttrDef, Reader, Entry, Attribute,
                        OperationalAttribute import ldap3
                  
                  conn = Connection(Server('adserver.com', port=389, use_ssl=False),
                                    auto_bind=AUTO_BIND_NO_TLS, user='DOMAIN\NTID',
                                    password='somepassword')
                  
                  conn.search(search_base='CN=GROUPNAME,OU=Groups,OU=Resources,OU=Global,DC=adserver.com',
                              search_filter='(objectCategory=person)', search_scope=SUBTREE,
                              attributes = ['sAMAAccountName'], size_limit=0) 
                  
                  print(conn.response_to_json())
                  

                  推荐答案

                  在搜索成员之前,您必须先从组本身中下拉成员列表.

                  Before you can search the members you must first pull down the list of members from the group itself.

                  conn.search(
                      search_base='CN=GROUPNAME,OU=Groups,OU=Resources,OU=Global,DC=adserver.com',
                      search_filter='(objectClass=group)',
                      search_scope='SUBTREE',
                      attributes = ['member']
                  )
                  
                  for entry in conn.entries:
                      print(entry.member.values)
                  

                  这将打印出成员列表作为专有名称.

                  This will print out a list of members as distinguished names.

                  然后您需要执行一个新的搜索,遍历每个成员并返回每个成员的 sAMAccountName.

                  You will then need to perform a new search that iterates through each of the members and returns the sAMAccountName for each member.

                  下面是完整代码的样子(可能需要调整):

                  Here is what the full code might look like (may need to be tweaked):

                  conn.search(
                      search_base='CN=GROUPNAME,OU=Groups,OU=Resources,OU=Global,DC=adserver.com',
                      search_filter='(objectClass=group)',
                      search_scope='SUBTREE',
                      attributes = ['member']
                  )
                  
                  for entry in conn.entries:
                      for member in entry.member.values:
                          conn.search(
                              search_base='OU=Global,DC=adserver.com',
                              search_filter=f'(distinguishedName={member})',
                              attributes=[
                                  'sAMAccountName'
                              ]
                          )
                  
                          user_sAMAccountName = conn.entries[0].sAMAccountName.values
                  
                          print(user_sAMAccountName)
                  

                  这篇关于ldap3 python 搜索组成员并检索他们的 sAMAcountName (Active Directory)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 Python LDAP 获得比服务器的 sizelimit 更多的搜索结果? 下一篇:如何检索 LDAP 数据库的所有属性

                  相关文章

                  • <bdo id='4yMGe'></bdo><ul id='4yMGe'></ul>

                  1. <i id='4yMGe'><tr id='4yMGe'><dt id='4yMGe'><q id='4yMGe'><span id='4yMGe'><b id='4yMGe'><form id='4yMGe'><ins id='4yMGe'></ins><ul id='4yMGe'></ul><sub id='4yMGe'></sub></form><legend id='4yMGe'></legend><bdo id='4yMGe'><pre id='4yMGe'><center id='4yMGe'></center></pre></bdo></b><th id='4yMGe'></th></span></q></dt></tr></i><div id='4yMGe'><tfoot id='4yMGe'></tfoot><dl id='4yMGe'><fieldset id='4yMGe'></fieldset></dl></div>
                  2. <small id='4yMGe'></small><noframes id='4yMGe'>

                    <tfoot id='4yMGe'></tfoot><legend id='4yMGe'><style id='4yMGe'><dir id='4yMGe'><q id='4yMGe'></q></dir></style></legend>