【问题标题】:Get-ADUser not returning all possible AD attributes when specifying all properties指定所有属性时,Get-ADUser 未返回所有可能的 AD 属性
【发布时间】:2018-12-22 06:56:20
【问题描述】:

我遇到过使用
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-UserPasswordExpiryTimeComputed 属性,否则它在生成的对象上根本不可用。

我已经知道在大多数情况下过滤 Properties * 并不是一个好主意,但我很好奇为什么 所有 AD DS 属性没有被枚举,而这正是我要问的要执行的 cmdlet。

这个问题是关于 Get-ADUser 的问题,但与 Get-ADObject cmdlet 的大多数其他行为一样,我认为这种行为扩展到大多数(如果不是全部)它们。

【问题讨论】:

标签: powershell active-directory


【解决方案1】:

以下代码应返回 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】:

    经过一些研究,ADObject 上有多种类型的属性 - DefaultExtendedConstructed 是其中的一些示例。

    Default 属性在与特定类型的 ADObject 匹配的所有 ADObject 查询上返回(ADUser 有自己的一组默认属性,ADGroup 有自己的一组,等等)

    Extended 属性默认不会返回,而是ADObject 上的隐式可枚举静态属性。

    Constructed 属性不是静态属性,而是根据属于ADObject 的其他属性的值计算得出的。我找不到任何关于此的信息,但我想枚举所有 Constructed 属性可能是一项昂贵的操作,因为这些值是计算出来的,因此需要通过 -Properties 请求明确 Get-ADObject cmdlet 的参数。

    这一切似乎都与ADObject 上的systemFlags 属性有关,这是设置属性类型的地方。根据我的测试,需要明确指定带有 Constructed (4)Non-Replicated (2) 标志的属性才能从 RSAT cmdlet 返回。

    来源

    msDS-UserPasswordExpiryTimeComputed Documentation

    List All Constructed Attributes on ADObject using an LDAP Filter

    Determining an Attribute Type

    SystemFlags Attribute

    【讨论】:

      猜你喜欢
      • 2020-05-01
      • 2015-08-18
      • 2015-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-25
      • 2022-01-26
      相关资源
      最近更新 更多