Create user using pyad without password expired

1k Views Asked by At

I'm using this code to create a user in active directory, using the pyad module in Python 2.7:

from pyad import *
pyad.set_defaults(ldap_server="IT-LHQ-DC1.LIFEALIKE.LAB", username="administrator", password="password")

ou = pyad.adcontainer.ADContainer.from_dn("ou=All_Users, dc=LIFEALIKE, dc=LAB")
new_user = pyad.aduser.ADUser.create("test.02", ou, password="password")

How can I create a user with the checkbox of "No Password Expire"?

1

There are 1 best solutions below

0
On BEST ANSWER

In AD, it's set via the userAccountControl attribute, which is a bit flag: https://msdn.microsoft.com/en-us/library/aa772300.aspx

The pyad library actually gives a method to modify this. This is what the documentation says:

set_user_account_control_setting(userFlag, newValue)

Sets a single setting in UserAccountControl.

UserFlag must be a value from ADS_USER_FLAG dictionary keys. Moreinformation can be found at http://msdn.microsoft.com/en-us/library/aa772300.aspx. newValue accepts boolean values

I am not a Python programmer, but if I understand this correctly, it would look something like this:

new_user.set_user_account_control_setting("DONT_EXPIRE_PASSWD", True)