use*_*216 2 python powershell ldap active-directory
PowerShell能够提取1492条记录的列表。当我将ldap3模块与Python配合使用时,我的记录数已达到1000条。请帮助我将Python代码更改为超出限制。
PowerShell输入: get-aduser -filter * -SearchBase "OU=SMZ USERS,OU=SMZ,OU=EUR,DC=my_dc,DC=COM" | Measure-Object
输出:计数:1492平均:总和:最大值:最小值:属性:
import json
from ldap3 import Server, \
Connection, \
AUTO_BIND_NO_TLS, \
SUBTREE, \
ALL_ATTRIBUTES
def get_ldap_info(u):
with Connection(Server('my_server', port=636, use_ssl=True),
auto_bind=AUTO_BIND_NO_TLS,
read_only=True,
check_names=True,
user='my_login', password='my_password') as c:
c.search(search_base='OU=SMZ Users,OU=SMZ,OU=EUR,DC=my_dc,DC=com',
search_filter='(&(samAccountName=' + u + '))',
search_scope=SUBTREE,
attributes=ALL_ATTRIBUTES,
size_limit = 0,
paged_criticality = True,
paged_size = None,
#attributes = ['cn'],
get_operational_attributes=True)
content = c.response_to_json()
result = json.loads(content)
i = 0
for item in result["entries"]:
i += 1
print(i)
get_ldap_info('*')
Run Code Online (Sandbox Code Playgroud)
如果将代码更改为使用extend.standard命名空间的paged_search方法,则应该能够检索到所有正在寻找的结果。
请注意,您将需要对响应对象进行不同的处理。
def get_ldap_info(u):
with Connection(Server('XXX', port=636, use_ssl=True),
auto_bind=AUTO_BIND_NO_TLS,
read_only=True,
check_names=True,
user='XXX', password='XXX') as c:
results = c.extend.standard.paged_search(search_base='dc=XXX,dc=XXX,dc=XXX',
search_filter='(&(samAccountName=' + u + '))',
search_scope=SUBTREE,
attributes=ALL_ATTRIBUTES,
#attributes = ['cn'],
get_operational_attributes=True)
i = 0
for item in results:
#print(item)
i += 1
print(i)
get_ldap_info('*')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1730 次 |
最近记录: |