指定所有属性时,Get-ADUser不会返回所有可能的AD属性

时间:2018-07-13 21:06:41

标签: powershell active-directory

我遇到了使用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的大多数其他行为一样,我认为这种行为扩展到了大多数(如果不是全部)。

2 个答案:

答案 0 :(得分:3)

以下代码应返回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一起使用,以检索单个用户的所有属性(在此示例中)。

答案 1 :(得分:1)

答案似乎是ADObject-DefaultExtendedConstructed上有多种类型的属性。

在与特定类型Default匹配的所有ADObject查询中返回

ADObject属性(ADUser有其自己的默认属性集,ADGroup具有自己的套装等)

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

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

这似乎都与Get-ADObject上的systemFlags属性有关,这是设置属性类型的地方。我的怀疑(我尚未广泛测试该理论)是需要明确指定带有ADObjectConstructed (4)标志的属性,以便从Non-Replicated (2)返回。

来源

msDS-UserPasswordExpiryTimeComputed Documentation

List All Constructed Attributes on ADObject using an LDAP Filter

Determining an Attribute Type

SystemFlags Attribute

相关问题