我正在使用python中的ldap模块将用户添加到Microsoft 2012 Active Directory。由于我能够成功地将用户添加到 AD,因此用户将在下次登录和帐户中添加为禁用选项。我尝试了很多选项来启用该帐户,但无法这样做。尝试在创建用户时启用帐户的选项,但这也不起作用。尝试修改功能,但仍然没有运气。谁能建议绕道解决上述问题?提前感谢
您需要在
创建条目后对其进行修改并设置 userAccountControl
属性。
userAccountControl
属性是一个位标志。
可以设置几种不同的enabled
状态。
-
512
- 是默认启用的帐户 -
67048
- 是密码未过期的已启用帐户
在启用活动目录帐户之前,请检查以下项目:
- 确保设置
userPrincipleName
属性,与电子邮件相同! - 确保已设置密码。如果没有,您可以通过修改
userAccountControl=544
而不是userAccountControl=512
或userAccountControl=67048
来启用用户。
然后您可以使用以下示例代码来启用用户:
from ldap3 import Server, Connection, MODIFY_REPLACE
server = Server('ldap://hostname', 389, use_ssl=False)
connection = Connection(server, user='DOMAIN/Administrator', password='AdminPass', auto_bind=True)
connection.modify(distinguishedName, {'userAccountControl': (MODIFY_REPLACE, [544])})
connection.modify(distinguishedName, {'userAccountControl': (MODIFY_REPLACE, [512])}) # for users' who have password.
connection.unbind()