AD GUI显示PowerShell返回空的属性

问题描述

我想获取所有AD用户及其创建时间和上次登录间的列表。首先,我使用了活动目录用户和计算机应用程序,并激活了高级功能。在属性编辑器中,我可以看到属性分别称为LastlogonWhenCreated
所以我这样做了:

$allUsers = Get-ADUser  -Filter * -Properties SamAccountName,Lastlogon,WhenCreated
$allUsers   | select SamAccountName,WhenCreated 

但是LastlogonWhenCreated仅适用于500个用户中的13个。在属性编辑器中,这些值被填充了很多...
当我仅使用Get-ADUser -Identity $User -Properties * Attribute Editor 查询具有这些值的一个用户时,我看到这些属性分别称为LastlogonDateCreated(这些值显示为空)。
所以我搜索了这些属性

$allUsers2= Get-ADUser  -Filter * -Properties SamAccountName,LastlogonDate,Created
$allUsers2   | select SamAccountName,Created

然后这13个人又获得了其他人所没有的信息。 有谁知道我如何获得这些价值观? (我将使用Export-CSV导出它们,因此在Excel中获取它们的另一种方法也可以)

解决方法

首先,查看您的cmdlet具有哪些属性:

$a = Get-ADUser -server 'DomenNameTest.en' -Identity 'makarovayu' -Properties *
$a | Get-Member
  • 我建议将接收到的数据复制到记事本中,以便以后复制可用的字段名称。

2-让我们声明一个数组并使用cmdlet尝试收集有关必填字段的信息

$userList = Get-ADUser -server 'DomenNameTest.en' -Properties SamAccountName,Name -Filter * |
#Do not forget that the comanlet has a limitation and can fall off on timeout.See how I work with each property in [select]
Select @{Name = "SamAccountName"; Expression={$_.SamAccountName}},@{Name = "Name"; Expression={$_.Name}} |
#Uploading data to [csv]
Export-Csv -Path "D:\Users\userTest\Desktop\userList.csv" -Append -NoTypeInformation -Encoding Default -Delimiter ';'
Remove-Variable a,userList  #Clear the variables
,

根据要求将我的评论作为答案。

首次尝试:

-Server上添加Get-ADUser开关,并使其查询与Active Directory用户和计算机当前连接的同一域控制器。可能是您要查询尚未同步的属性(尤其是lastLogon时间戳,我相信该时间戳每14天仅同步一次,除非您为ms-DS-Logon-Time-Sync-指定了其他值域默认命名上下文上的时间间隔属性。)

--> 不适用,因为您是在DC本身上运行的

第二次尝试:

尝试使用$searcher = [adsisearcher]'(&(objectCategory=person)(objectClass=user))'; $searcher.FindAll()中的ADSI

--> 结果与Get-ADUser相同;仍然为空值

第三次尝试:

检查PowerShell版本

--> 显然,DC的PS版本为4。在5.1版本中,它有效