正在尝试使用pyad在活动目录中创建用户,并且成功。当我尝试udpate用户的姓氏时,它会抛出“属性错误”。我检查了AD中的属性,并且在程序中使用了相同的属性。
代码:
import pyad
from pyad import *
pyad.set_defaults(ldap_server="xxx.com", username="xxx\test", password="xxx@123")
ou = pyad.adcontainer.ADContainer.from_dn("OU=TestOU,DC=xxx,DC=com")
new_user = pyad.aduser.ADUser.create("Python", ou, password="abc@123")
print("User Created Successfully")
user = pyad.aduser.ADUser.from_cn("Python")
user.update_attribute("givenName", "PYTHON")
user.update_attribute("displayName","PYTHON-NEW")
user.update_attribute("mail","python@python.org")
user.update_attribute("st","XXX")
user.update_attribute("initials","py")
**user.udpate_attribute("sn","p")**
user.update_attribute("telephonenumber","9176665636")
user.force_pwd_change_on_login()
错误:
File "C:/Users/sheikkalidhr/Desktop/aduser.py", line 14, in <module>
user.udpate_attribute("sn","p")
File "D:\backup\New folder\lib\site-packages\pyad\adobject.py", line 202, in __getattr__
raise AttributeError(attribute)
AttributeError: udpate_attribute
答案 0 :(得分:1)
如果其他人会寻找答案,我在这里写了一个回复。 sn 属性对于更新 AD“姓氏”字段是正确的,但我在创建新用户时使用了所有属性。请查看下面的示例。
from pyad import *
pyad.set_defaults(ldap_server="xxx.com", username="xxx\test", password="xxx@123")
ou = pyad.adcontainer.ADContainer.from_dn("OU=TestOU,DC=xxx,DC=com")
new_user = pyad.aduser.ADUser.create("Python", ou, password="abc@123",
optional_attributes={
"givenName" : "PYTHON",
"displayName" : "PYTHON-NEW",
"mail" : "python@python.org",
"st" : "XXX",
"initials" : "py",
"sn" : "p",
"telephonenumber" : "9176665636"
})
希望对你有帮助