powershell - 指定所有属性时,Get-ADUser 未返回所有可能的 AD 属性
问题描述
我遇到过使用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 的大多数其他行为一样,我认为这种行为扩展到大多数(如果不是全部)它们。
解决方案
以下代码应返回 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 一起使用以检索单个用户的所有属性(在此示例中)。
推荐阅读
- javascript - 数字显示为 NaN
- tensorflow - tf.keras.layers.Conv2D 获取内核值
- .net - 将字符串拆分为行并使用.net检查当前行和下一行
- laravel - 更新当前布尔值的相反值
- php - Javascript 时间戳在 Laravel 中被 Carbon 解析为错误日期
- php - 附加到 XML 的末尾时,formatOutput 不起作用,但在第一次创建文件时,formatOutput 工作正常
- css - 将反应门户居中在父元素的顶部
- r - muthist 中没有空格的盒子
- javascript - 在特定单元格不为空时在 Google 表格中运行一个脚本,将公式生成到单元格中
- windows - 错误:在Windows中通过cmd在c盘中创建文件?