代码之家  ›  专栏  ›  技术社区  ›  codewario

当指定所有属性时,get aduser不返回所有可能的AD属性

  •  7
  • codewario  · 技术社区  · 6 年前

    我遇到了一种情况,在使用时没有枚举特定的属性 Get-ADUser -Properties * . 例如,以下代码没有列出 msDS-UserPasswordExpiryTimeComputed 属性,即使它存在并且我可以将其指定为 -Properties 参数,使其返回,并可以处理其值。

    # Does not return msDS-UserPasswordExpiryTimeComputed
    Get-ADUser username -Properties *
    
    # This works to get the msDS-UserPasswordExpiryTimeComputed attribute returned
    Get-ADUser username -Properties msDS-UserPasswordExpiryTimeComputed
    
    # If I really want all properties and this one
    # I have to specify it alongside *
    Get-ADUser username -Properties *, msDS-UserPasswordExpiryTimeComputed
    

    这不仅仅是从显示中省略属性的情况,我需要显式地声明 msds用户密码到期时间已计算 属性,否则它在结果对象上不可用。

    我已经知道过滤 Properties * 在大多数情况下不是个好主意,但我很好奇为什么 全部的 当这正是我要求Cmdlet执行的操作时,不会枚举AD DS属性。

    这个问题是关于 Get-ADUser 但和其他大多数行为一样, Get-ADObject 我假设此行为扩展到了大多数(如果不是全部)Cmdlet。

    2 回复  |  直到 6 年前
        1
  •  3
  •   TobyU    6 年前

    以下代码应返回AD用户的所有属性(objectclass=user的所有属性):

    $properties = Get-ADObject -SearchBase (Get-ADRootDSE).SchemanamingContext -Filter {name -eq "User"} -Properties MayContain,SystemMayContain | `
    Select-Object @{name="Properties";expression={$_.maycontain+$_.systemmaycontain}} | `
    Select-Object -ExpandProperty Properties
    
    Get-ADUser -Identity username -Properties $properties | fl $properties
    

    首先,它检索并将所有用户属性保存到一个数组中,然后将属性数组与get aduser一起用于检索单个用户的所有属性(在本例中)。

        2
  •  1
  •   codewario    6 年前

    答案似乎是在 ADObject Default , Extended Constructed 就是这些例子。

    违约 返回所有 对象 匹配特定类型的查询 对象 ( ADUser 有自己的默认属性集, ADGroup 有自己的套装等)

    扩展 默认情况下不返回属性,但在 对象 .

    构建 属性不是静态属性,而是根据属于 对象 . 我找不到任何关于这个的信息,但我想列举一下 构建 属性可能是一个昂贵的操作,因为值是计算出来的,因此需要 明确地 通过请求 -Properties 的参数 Get-ADObject Cmdlet。

    这一切似乎都与 systemFlags 属性 对象 ,这是设置属性类型的地方。我的怀疑(我没有广泛测试过这个理论)是 Constructed (4) Non-Replicated (2) 需要显式指定标志以便从 cmdlet .

    来源

    msDS-UserPasswordExpiryTimeComputed Documentation

    List All Constructed Attributes on ADObject using an LDAP Filter

    Determining an Attribute Type

    SystemFlags Attribute