zakird / pyad

Python Active Directory Tools | *Not actively maintained*
http://zakird.github.io/pyad/
176 stars 72 forks source link

Com #122

Open nirr3 opened 4 years ago

nirr3 commented 4 years ago

Hello,

I am trying to pull a list of AD Group users that have logged in recently, and when their account expires.

See code snippet below:

import pyad.adquery q = pyad.adquery.ADQuery()

q.execute_query( attributes = ["distinguishedName", "mail", "whenCreated", "Manager", "lastLogon","accountExpires","userPrincipalName"], where_clause = "objectClass = 'user'",

base_dn = "OU=users, DC=domain, DC=com"

)

for row in q.get_results(): print(row["Manager"],row["mail"], row["distinguishedName"], row["whenCreated"] , row["lastLogon"],row["accountExpires"],row["userPrincipalName"])

For some of the elements such as LastLogonDate, its return a COMObject instead of a date. <COMObject > <COMObject >

Any help is appreciated

jarhead8795 commented 4 years ago

Try this. import win32com.client import pyad.pyadutils

last_logon = pyad.pyadutils.convert_datetime(row['lastLogon'])

To check the type use isinstance(your_var, win32com.client.CDispatch)