zakird / pyad

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

Doc: what attributes are available for person object? #35

Closed maphew closed 7 years ago

maphew commented 9 years ago

This is probably a documentation issue, not a bug; with #34 solved I bump into my next question: What attributes are available for reporting from a person object?

from pyad import adgroup
group = adgroup.ADGroup.from_dn(group_name + org_unit + domain)
members = group.get_members()
peep = members[70]
print peep.displayname, peep.description

Successful result:

Perry.Smith Tiddlywinks Administrator

So have something that works for displaying the name and description for a single user but I want to display more information such as phone number, office location, etc. I don't know how to find out attributes are available for reporting. For example peep.displayname which clearly works is not in the list returned by dir(peep).

zakird commented 9 years ago

Look at get_allowed_attributes in the docs.

maphew commented 9 years ago

thanks! that does the trick. Perhaps this example could be folded into the docs somewhere to help someone else:

'''Display all attributes for the selected group member which contain values'''
from pyad import adgroup
group = adgroup.ADGroup.from_dn(group_name + org_unit + domain)
members = group.get_members()
peep = members[5] # select 6th group member
for a in peep.get_allowed_attributes():
    value = getattr(peep, a)
    if value:
        print '{0:30}:{1}'.format(a, value)