【问题标题】:Python using pyad to display attributes, not getting logonHoursPython使用pyad显示属性,没有得到logonHours
【发布时间】:2018-11-09 15:13:15
【问题描述】:

我一直在尝试让logonHours 显示,同时在Python 3.7 中使用pyad。当我去显示 logonHours 时,它给了我一个输出 memory at 0x0000000003049708

不确定如何显示该数据。所有其他属性都正常显示。

from pyad import *
q = pyad.adsearch.ADQuery()
q.execute_query(
    attributes= ["distinguishedName", "givenName", "userWorkstations","homeDirectory", "homeDrive", "logonHours"],
    where_clause = "objectClass = '*'",
    base_dn = "OU=Graphic Design Students, DC=someplace, DC=com"
)
adoutput = []
for row in q.get_results():
    adoutput.append(row["distinguishedName"])
    adoutput.append(row["givenName"])
    adoutput.append(row["userWorkstations"])
    adoutput.append(row["homeDirectory"])
    adoutput.append(row["homeDrive"])
    adoutput.append(row["logonHours"])
adoutput = [x for x in adoutput if x != None]

print(adoutput)

我的输出如下:

<memory at 0x0000000003049708>
<memory at 0x00000000030497C8>
<memory at 0x0000000003049888>
<memory at 0x0000000003049948>
<memory at 0x0000000003049A08>
<memory at 0x0000000003049AC8>

【问题讨论】:

  • 所以不只是 logonHours 搞砸了?好像都是?试试print(row["distinguishedName"]) 看看是否能提供正确的数据。也许它只是在您的阵列中弄乱了。 (我对python不是很了解)
  • 'print(row["distinguishedName"])' 显示得很好,以及其他属性。 logonHours 是唯一一个作为内存位置输出的。我认为“logonHours”作为某个对象显示为内存位置。仍在尝试以某种可用的形式获得它。

标签: python-3.x active-directory pyad


【解决方案1】:

使用

row["logonHours"].tobytes() 

获取字节值——您将看到与 ADSIEdit 显示的属性值相同的相当神秘的东西。

诀窍就是把它变成神秘的东西。 https://social.technet.microsoft.com/Forums/exchange/en-US/545552d4-8daf-4dd8-8291-6f088f35c2a4/how-is-the-logon-hours-attribute-set-in-active-directory-windows-server-2008-r2-?forum=winserverDS

很好地解释了值的编码方式

【讨论】:

    【解决方案2】:

    LogonHours 是一个 COM 对象。

    以下是我处理 logonHours 属性的方法。在我的循环中,我检查了数据类型:

    import pyad.pyadutils
    import win32com.client
    if isinstance(v, win32com.client.CDispatch):
        value = pyad.pyadutils.convert_datetime(v)
    

    这给了我一个可以使用的日期时间对象。希望这对某人有所帮助。

    【讨论】:

      【解决方案3】:

      使用@LisaJ 的答案中链接的the article,这里有一些您可以使用此属性的应用程序。希望这可以帮助某人。

      #Convert the array to a list of which hours each day the account is logged in
      weekList = []
      for shift_1, shift_2, shift_3 in zip(*[iter(row["logonHours"].tobytes())]*3):
          weekList.append(format(shift_1, '08b') + format(shift_2, '08b') + format(shift_3, '08b'))
      
      #Total the hours for each day
      totalHours = {}
      for i, (shift_1, shift_2, shift_3) in enumerate(zip(*[iter(row["logonHours"].tobytes())]*3)):
          totalHours[i] = len((format(shift_1, '08b') + format(shift_2, '08b') + format(shift_3, '08b')).replace("0", ""))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-01
        • 2013-04-20
        • 2010-11-02
        相关资源
        最近更新 更多