2

I'm having problems trying to access the active directory user attribute using pyad. Here is my code:

user = pyad.aduser.ADUser.from_cn("tuser")
print user.get_attribute(lastLogonTimestamp")

These are the printed attributes:

C:\Users\tuser\Desktop\docb0t>python docb0t.py
[<COMObject GetEx>]

I have no idea how to retrieve the value off that object. How can I do it?

Bharel
  • 23,672
  • 5
  • 40
  • 80
PuN1sh3r
  • 91
  • 1
  • 8

1 Answers1

5

I ran into this same issue and after a little digging figured out the answer. You need to run the attribute through the pyadutils.convert_datetime function.

print pyadutils.convert_datetime(user.get_attribute('lastLogonTimeStamp', False))

Enjoy!

TriSkulL

TriSkulL
  • 51
  • 2
  • hey man sorry for the late response but until now i got to work on the project again. it did work... thanks lots – PuN1sh3r Apr 20 '14 at 03:44
  • For some reason I get: NameError: name 'pyadutils' is not defined When I include it with from pyad import pyadutils, aduser, I get this error: OSError: [Errno 22] Invalid argument – Typewar Sep 19 '18 at 11:21
  • Figured it out. the "False" thing in the code was apparently very important. Thank you! – Typewar Sep 20 '18 at 08:44