1

Am trying to create users in active directory using pyad and it is successful. when i try to udpate last name of user, it is throwing "attribute error". I checked with attributes in AD and it is same what am using in program.

The code:

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()

Error:

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
funie200
  • 3,688
  • 5
  • 21
  • 34
Sheik Kalidh
  • 33
  • 1
  • 8

1 Answers1

2

I wrote a reply here if someone else will looking for an answer. sn attribute is correct for update the AD "Last name" -field, but I use to give all the attributes when creating the new user. Please check out the example below.

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"
   })

Hope this is helpful

Joonaksu
  • 21
  • 3