Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AD GUI显示PowerShell返回为空的属性_Powershell_Active Directory - Fatal编程技术网

AD GUI显示PowerShell返回为空的属性

AD GUI显示PowerShell返回为空的属性,powershell,active-directory,Powershell,Active Directory,我想获得所有广告用户及其创建时间和上次登录时间的列表。首先,我使用了Active Diretory用户和计算机应用程序并激活了高级功能。在属性编辑器中,我可以看到属性被称为LastLogon和when-created 所以我这样做了: $allUsers = Get-ADUser -Filter * -Properties SamAccountName,LastLogon,WhenCreated $allUsers | select SamAccountName,LastLogon,Whe

我想获得所有广告用户及其创建时间和上次登录时间的列表。首先,我使用了Active Diretory用户和计算机应用程序并激活了高级功能。在属性编辑器中,我可以看到属性被称为
LastLogon
when-created

所以我这样做了:

$allUsers = Get-ADUser  -Filter * -Properties SamAccountName,LastLogon,WhenCreated
$allUsers   | select SamAccountName,LastLogon,WhenCreated 
但是,
LastLogon
when-created
仅适用于500个用户中的13个。在属性编辑器中,这些值将被填充更多…
当我使用
Get ADUser-Identity$user-Properties*
在属性编辑器中仅查询一个具有这些值的用户时,我看到这些属性被称为
lastlogondata
Created
(值显示为空)。
所以我搜索了这些属性:

$allUsers2= Get-ADUser  -Filter * -Properties SamAccountName,LastLogonDate,Created
$allUsers2   | select SamAccountName,LastLogonDate,Created
这13个人也有其他人没有的信息。
有人知道我是如何得到这些价值观的吗?(我将使用导出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

首先,查看您的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登录时间同步间隔属性指定了不同的值。)

-->
未应用,因为您正在DC本身上运行此操作

第二次尝试:

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

-->
与使用
获取ADUser
的结果相同;仍然是空值

第三次尝试:

检查PowerShell版本


-->
显然DC有PS版本4。对于5.1版,它可以按照我的评论作为答案的要求运行

第一次尝试:

添加
-Server
开关,打开
Get ADUser
,让它查询您当前与Active Directory用户和计算机连接的同一个域控制器。可能是您请求的属性尚未同步(特别是lastLogon时间戳,我认为它每14天只同步一次,除非您在域默认命名上下文中为ms DS登录时间同步间隔属性指定了不同的值。)

-->
未应用,因为您正在DC本身上运行此操作

第二次尝试:

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

-->
与使用
获取ADUser
的结果相同;仍然是空值

第三次尝试:

检查PowerShell版本


-->
显然DC有PS版本4。在5.1版中,它可以工作

我首先检查了userproperties。当我查看用户的properties>attribtue编辑器时,它显示属性名为
When-changed
lastLogon
,并且两者都已填充。当我在PowerShell中查询该用户时(
Get ADUser-Identity$user-Properties*
),我看到该属性被称为
lastLogonData
Created
都是空的。我喜欢您计算select的属性,并在最后删除变量,但由于结果仍然是空的,所以我并不认为这很重要……我首先检查了userproperties。当我查看用户的properties>attribtue编辑器时,它显示属性名为
When-changed
lastLogon
,并且两者都已填充。当我在PowerShell中查询该用户时(
Get ADUser-Identity$user-Properties*
),我看到该属性被称为
lastLogonData
Created
都是空的。我喜欢你计算select的属性,并在最后删除变量,但我不认为这有什么关系,因为结果仍然是空的…只是在黑暗中拍摄,但是,如果您使用Get ADUser上的
-Server
开关,让它查询您当前与Active Directory用户和计算机连接的同一个域控制器,该怎么办。可能是您请求的属性尚未同步(特别是lastLogon时间戳,我认为它每14天只同步一次,除非您在域默认命名上下文中为
ms DS登录时间同步间隔
属性指定了不同的值。)@Theo尝试了相同的结果。但是我在DC上执行这个代码。大多数用户都是在过去3年中创建的,我知道有很多用户已经有两个月没有登录了……在我看来,在ADUC中看到日期似乎很奇怪,但PowerShell无法获取这些日期。。您是否尝试过使用不同的(域管理员)凭据?如果这是关于查找过时的用户对象,您可能希望尝试
搜索ADAccount-AccountInactive-DateTime((Get Date).AddMonths(-4).Date)-UsersOnly
以查看使用情况