Esempio n. 1
0
string. It provides useful defaults for all fields so here
we're not supplying a base for the query (which will be
the root of our AD) nor a scope (which will be subtree).

core.query creates an ad-hoc connection to AD and issues the
query string you supply. You can specify as keyword arguments
any properties which the ADO connection support. The ADO
flags are space-separated titlecase words; the Python equivalents
are underscore_delimited lowercase.
"""
from active_directory import core
qs = core.query_string (
  filter = core.and_ ("objectClass=computer", "OperatingSystem=Windows Server*"),
  attributes=['cn', 'OperatingSystem', 'OperatingSystemVersion']
)
for computer in core.query (qs, sort_on="cn"):
  print "%(cn)s: %(OperatingSystem)s [%(OperatingSystemVersion)s]" % computer

print

"""This example illustrates every option in the query string builder. It
uses one query to pick out one (arbitrary) OU and then searches only
that OU, using it as the base for the query string and specifying no
subtree searching. The distinguishedName and whenCreated are returned
"""
from active_directory import core
for ou in core.query (
  core.query_string ("objectCategory=organizationalUnit"),
  page_size=1
):
  base = ou['ADsPath']
Esempio n. 2
0
"""By default, the active_directory package assumes that you're
using standard Windows authentication to bind to AD. But there
are two other options: anonymous authentication; and user/password
sign-on. If you need either of those, you'll have to create a
credentials object and pass it around to any function which needs
to bind or query AD.
"""

"""Query AD as an anonymous user
"""
from active_directory import core, credentials

qs = core.query_string (base="LDAP://sibelius")
for i in core.query (query_string=qs, connection=core.connect (cred=credentials.Anonymous)):
  print i