Select Page

Sometimes it’s nice to be able to take a quick look at your Active Directory (AD) users and see what’s there and who is actually active. Here’s a quick little Python program to list out your current users.

It’s not a very heavy duty program thanks to the ldap3 module. You can install the module easily using pip install ldap3. The project page has more info and documentation.

We start off by setting variables with our custom values that we are going to need to use in the program. I would imagine that it’s obvious that you should replace the values used in the assignments with your own values.


Next we create an instance of the LDAP3 Server class. We can then use the server as a parameter to the Connection. Once we have our connection instance then we can perform a search in AD. The key is that we are querying for (objectclass=person). That will give us the person objects from AD. Then it’s a quick little loop to display all of the results. Here’s the code:


If you would like to perform more complex searches there is a set of basic syntax for querying. The project page provides more details on searching the Directory Information Tree.

The list_users program code is all yours to use.

When have you had to dig through your AD and see who is doing what?

Share This