I have a Python script which read a PDF document and create an AD user account related the data it gets. I want in directory shown as John Doe instead of user account jdoe. Here what I have done so far:
from pyad import *
firstname = 'John'
lastname = 'Doe'
username = firstname[0].lower() + lastname.lower()
displayname = firstname + ' ' + lastname
password = 'Secret124!'
pyad.set_defaults(ldap_server="dcx", username="admin", password="Secret")
ou = pyad.adcontainer.ADContainer.from_dn("OU=Test-accounts, DC=company, DC=com")
new_user = pyad.aduser.ADUser.create(username, ou, password=password,
optional_attributes={
'givenname' : firstname,
'sAMAccountName' : username,
'displayName' : displayname,
'sn' : lastname
})
new_user.update_attribute('displayName', displayname)
That runs without error but the displayName is still jdoe. How to change that using Python?
I changed the method using a displayname as useraccount and then give username as attributes. See below: