Create users on Microsoft Active Directory using a Scripting Language
Question: I need to create and/or update the Students users in the school I work in. I
only have access to the "Remote Control" not directly on the server and I have
been told, that I will be able to remotely create, update and delete users and
groups.

The problem is: I must create a lot users every 1/2 Year and so, I want to do
that automatically. I have a database dump from the students and the classes
so I could read that out in a scripting language like Python, PHP or in a
Java/C++ program (Python would be my favourite)

I am looking for a way to create the groups and the users with a scripting
lanugage on a remote computer and if it also works I want to create
sharedrives and give the users/groups access to that automatically.

Each half year, the users get updated in the new class so I must fetch a
record of the users and check it against the new students list and update the
users.

Does anyone know some bindings/remote controll libraries/classes for Microsoft
Active Directory Management for one of those Programming Languages?


Answer: I've used PyAD for AD-work and was satisfied with the result. Here is a short
example of creating a user.

    
    
    from pyad import *
    pyad.set_defaults(ldap_server="dc1.domain.com", username="service_account", password="mypassword")
    ou = ADContainer.from_dn("ou=users, dc=domain, dc=com")
    new_user = ADUser.create("Daniel", ou, password="Secret")
    

It is also possible to edit users and groups using `set_attribute` and add
users to groups. For example:

    
    
    new_user.set_attribute("mail", "daniel@example.com")
    group = ADGroup.from_dn("so-users")
    group.add_member(new_user)
    

And to delete:

    
    
    new_user.delete()
    

You can find the documentation at: <https://zakird.com/pyad/>

Note: I do not have access to a Windows environment so this code isn't tested,
so expect some detail to be wrong.

