Python – Assign user to a sub OU

I want to create an user in a Windows Active-Directory to a special OU. I got the right code already that works fine. But I want to create this user to a sub OU e.g.: Company -> User -> Sales.
My code is the following:

def addUser():
    pyad.set_defaults(ldap_server="domain.local", username="Administrator", password="mypassword")
    ou = pyad.adcontainer.ADContainer.from_dn("ou=Company, ou=User, ou=Sales, dc=domain, dc=local")
    new_user = pyad.aduser.ADUser.create("Name", ou, password="UserPassword")
    print("sucess")

Is it possible to create the user directly in my OU or do I have to move him afterwards?

Source: Windows Questions

LEAVE A COMMENT