0

python3 pyad 模块有问题。我想用一些信息查询我的活动目录环境以获取所有 PC 以及它们是否已启用。

这是代码:

q = pyad.adquery.ADQuery()
q.execute_query(
    attributes = ["CN", "OperatingSystem", "OperatingSystemVersion", "Description", "Enabled"],
    where_clause = "objectClass = 'Computer'",
    base_dn = "OU=Client,OU=####,OU=########,DC=###############,DC=########,DC=local"
)

ad_result = []
for row in q.get_results():
    ad_result.append(row)
    print(row)

这就是我要回来的:

{'Enabled': None, 'Description': None, 'OperatingSystemVersion': '10.0 (17763)', 'OperatingSystem': 'Windows 10 Pro', 'CN': '<PC NAME>'}
{'Enabled': None, 'Description': None, 'OperatingSystemVersion': '10.0 (17763)', 'OperatingSystem': 'Windows 10 Pro', 'CN': '<PC NAME>'}
{'Enabled': None, 'Description': None, 'OperatingSystemVersion': '10.0 (17763)', 'OperatingSystem': 'Windows 10 Pro', 'CN': '<PC NAME>'}
{'Enabled': None, 'Description': None, 'OperatingSystemVersion': '10.0 (17763)', 'OperatingSystem': 'Windows 10 Pro', 'CN': '<PC NAME>'}
{'Enabled': None, 'Description': None, 'OperatingSystemVersion': '10.0 (17763)', 'OperatingSystem': 'Windows 10 Pro', 'CN': '<PC NAME>'}
{'Enabled': None, 'Description': None, 'OperatingSystemVersion': '10.0 (17763)', 'OperatingSystem': 'Windows 10 Pro', 'CN': '<PC NAME>'}
{'Enabled': None, 'Description': None, 'OperatingSystemVersion': '10.0 (17763)', 'OperatingSystem': 'Windows 10 Pro', 'CN': '<PC NAME>'}

所以我的问题是,我没有将“启用”状态返回为TrueFalse,而是只得到None。当我通过 Powershell 查询时它工作正常,但我真的很想使用 python。我不想将一些 Powershell csv 导出到我的脚本中。如果有人有任何想法,我将不胜感激,谢谢。

4

1 回答 1

0

我不知道为什么会观察到这种行为,但我知道从哪里获取“启用”属性:

comp = adcomputer.ADComputer.from_cn("xxxxxxxx")
comp.get_user_account_control_settings()

将产生:

{'SCRIPT': False,
 'ACCOUNTDISABLE': False,
...

对于启用的机器和禁用的机器:

{'SCRIPT': False,
 'ACCOUNTDISABLE': True,
...

对于描述字段:

comp.get_allowed_attributes()

如果属性名称在上述调用的输出中,您可以使用以下命令进行查询:

comp.get_attribute('description')
于 2021-01-05T15:49:56.857 回答