Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Com #122

Open
nirr3 opened this issue Nov 10, 2019 · 0 comments
Open

Com #122

nirr3 opened this issue Nov 10, 2019 · 0 comments

Comments

@nirr3
Copy link

nirr3 commented Nov 10, 2019

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
Copy link

jarhead8795 commented Jan 10, 2020

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants