Utilities

pyad.pyad.from_cn(common_name, search_base=None, options={}) pyad.adobject.ADObject[source]

Generates ADObject based on common name

pyad.pyad.from_dn(distinguished_name, options={}) pyad.adobject.ADObject[source]

Generates ADObject based on distinguished name

pyad.pyad.from_guid(guid, options={}) pyad.adobject.ADObject[source]

Generates ADObject based on GUID

pyad.pyadutils.convert_bigint(obj)[source]
pyad.pyadutils.convert_datetime(adsi_time_com_obj)[source]

Converts 64-bit integer COM object representing time into a python datetime object.

pyad.pyadutils.convert_error_code(error_code)[source]

Convert error code from the format returned by pywin32 to the format that Microsoft documents everything in.

pyad.pyadutils.convert_guid(guid_object)[source]
pyad.pyadutils.convert_sid(sid_object)[source]
pyad.pyadutils.convert_timespan(obj)[source]

Converts COM object representing time span to a python time span object.

pyad.pyadutils.escape_path(path)[source]
pyad.pyadutils.generate_ads_path(distinguished_name: str, type: str, server: Optional[str] = None, port: Optional[int] = None) str[source]

Generates a proper ADsPath to be used when connecting to an active directory object or when searching active directory.

Parameters
  • distinguished_name (str) – DN of object or search base such as ‘cn=John Smith,cn=users,dc=example,dc=com’

  • type (str) – the connection type, either ‘LDAP’, ‘LDAPS’, or ‘GC’

  • server (str, optional) – FQDN of domain controller if necessary to connect to a particular server, defaults to the global catalog server

  • port (int, optional) – port number for directory service if not default port. If port is specified, server must be specified.

Raises

TypeError – Invalid type for type

Returns

the ADsPath to be used when connecting to Active Directory

Return type

str

pyad.pyadutils.generate_list(input)[source]
pyad.pyadutils.interpret_com_exception(excp, additional_info={})[source]
pyad.pyadutils.pass_up_com_exception(excp, additional_info={})[source]
pyad.pyadutils.validate_credentials(username: str, password: str, domain: str = None) win32.PyHandle[source]

Validates credentials; returns a PyHANDLE object with a bool value of True if the credentials are valid, else returns None. Note that if the user would not be able to log on; for example, due to the account being expired; None will be returned.

Parameters
  • username (str) – username

  • password (str) – password

  • domain (str, optional) – domain name, defaults to None

Returns

PyHandle Object with a bool of true. or None

Return type

win32.PyHandle