Skip to main content

An Object-Oriented Active Directory management framework built on ADSI

Project description

Introduction

pyad is a python library designed to provide a simple, object oriented interface to Active Directory through ADSI on the Windows platform. pyad requires pywin32, available at http://sourceforge.net/projects/pywin32.

pyad is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

A copy of the GNU General Public License is available at <http://www.gnu.org/licenses/>.

Basics

Active Directory objects are represented by standard python objects. There are classes for all major types of Active Directory objects: ADComputer, ADContainer, ADDomain, ADGroup, ADUser, all of which inherit from ADObject. It is possible to connect to objects via CN, DN, and GUID. The type will automatically be selected at runtime. Example:

from pyad import pyad
u = pyad.from_cn("user1")
c = pyad.from_dn("cn=WS1,ou=Workstations,dc=domain,dc=com")
g = pyad.from_cn("group1")

It is possible to read attribute values in two ways.:

print u.displayName
print u.get_attribute("displayName")

Attributes can be set by calling clear_attribute, update_attribute, update_attributes, append_to_attribute, and remove_from_attribute. Example:

u.update_attribute("displayName", "new value")

There are other helper methods available for managing attributes. We provide further examples below for common actions for each object type.

Group Examples

  1. Finding group members:

    for object in g.get_members(recursive=False):
            print object
  2. Adding an object to a group:

    g.add_members(u)

or:

u.add_to_group(g)
  1. Set group scope:

    g.set_group_scope("UNIVERSAL")

User Examples

  1. Set password:

    u.set_password("new_plaintext_password")
  2. Force password change on login:

    u.force_pwd_change_on_login()

Container Examples

  1. Find all objects in an OU:

    ou = pyad.adcontainer.ADContainer.from_dn("OU=Workstations,DC=company,DC=com")
    for obj in ou.get_children():
            print obj
  2. Recursively find all computers below a certain OU:

    for c in ou.get_children(recursive=True, filter=[pyad.adcomputer.ADComputer]):
            print c

Creating Objects

It is possible to create objects through pyad. Example:

ou = pyad.adcontainer.ADContainer.from_dn("OU=Workstations,DC=company,DC=com")
c = pyad.adcomputer.ADComputer.create(
        name = 'myworkstation2',
        container_object = ou,
        enable = True,
        optional_attributes = dict(
                description = "newly created computer"
        )
)

Querying

It is also possible to make queries to find objects. Example:

q = pyad.adquery.ADQuery()
q.execute_query(
        attributes = ['distinguishedname', 'description'],
        where_clause = "cn like 'ws%'",
        base_dn = "dc=company,dc=com"
)
for r in q.get_results():
        print r['distinguishedname']

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyad-0.4.19.tar.gz (17.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyad-0.4.19-py2.7.egg (45.2 kB view details)

Uploaded Egg

pyad-0.4.19-py2.6.egg (45.3 kB view details)

Uploaded Egg

File details

Details for the file pyad-0.4.19.tar.gz.

File metadata

  • Download URL: pyad-0.4.19.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyad-0.4.19.tar.gz
Algorithm Hash digest
SHA256 ce68a6e7b343735ee7b4fb0e13a7b586f6645d4fd0d4c5cdf4c319e78775db14
MD5 0e4e98a51afa574091a1a601bc2086fe
BLAKE2b-256 9b8f33bccac0292bbd09e642f635b0ce66810ab3a6f45ac6fed95a789eebacdb

See more details on using hashes here.

File details

Details for the file pyad-0.4.19-py2.7.egg.

File metadata

  • Download URL: pyad-0.4.19-py2.7.egg
  • Upload date:
  • Size: 45.2 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyad-0.4.19-py2.7.egg
Algorithm Hash digest
SHA256 2e455ac13b9ea2df87bf03f041a0b8f2de4ba06fef9a4a23a19cb3aaecb8a70d
MD5 4ad1c891e5e964a5b1c3d6cea5fb6e4c
BLAKE2b-256 371fd1509e3cecc40dd3885e3eb39a9cc6b849743277d2d27109cfffa0185779

See more details on using hashes here.

File details

Details for the file pyad-0.4.19-py2.6.egg.

File metadata

  • Download URL: pyad-0.4.19-py2.6.egg
  • Upload date:
  • Size: 45.3 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyad-0.4.19-py2.6.egg
Algorithm Hash digest
SHA256 20b2b66f4357cd582b2c3d02bb2f30f15381f5a48f1b1a372a3d96b57efe6817
MD5 e6526e7d356919d8bb289218f774740c
BLAKE2b-256 297a7715da750088e1e3d0d5fe5d5058f8419d9def56dfb52458a19e5fa8fc5f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page