[英]Properties not showing correctly for ADUsers in Powershell
I found something that was sort of odd while looking through ADUsers in Powershell. 在Powershell中查看ADUsers时,发现有些奇怪的地方。
If I typed the following: 如果输入以下内容:
PS> Get-ADUser Xuser -Properties PasswordLastSet, LastLogonDate
I would get an output like this: 我会得到这样的输出:
DistinguishedName : CN=Xuser,OU=Domain Users,DC=LocalDC,DC=local
Enabled : True
GivenName :
LastLogonDate : 7/14/2016 8:24:03 AM
Name : Xuser
ObjectClass : user
PasswordLastSet : 7/1/2016 11:48:37 AM
SamAccountName : Xuser
Surname :
UserPrincipalName :
As you can see, I have timestamps on PasswordLastSet and LastLogonDate. 如您所见,我在PasswordLastSet和LastLogonDate上都有时间戳。
However, if I type this following: 但是,如果我输入以下内容:
PS> $user = Get-ADUser Xuser
PS> $user.LastLogonDate -eq $null
PS> True
PS> $user.PasswordLastSet -eq $null
PS> True
To make sure nothing was messed up, I typed: 为了确保没有混乱,我输入:
PS> $user
DistinguishedName : CN=Xuser,OU=Domain Users,DC=LocalDC,DC=local
Enabled : True
GivenName :
LastLogonDate :
Name : Xuser
ObjectClass : user
PasswordLastSet :
SamAccountName : Xuser
Surname :
UserPrincipalName :
For some reason, that information shows $null. 由于某种原因,该信息显示$ null。
One thing I noticed is that when I typed: 我注意到的一件事是,当我键入时:
PS> $user = Get-ADUser Xuser
It doesn't gather PasswordLastSet and LastLogonDate by default--you have to request that specific information as parameters with the -Properties
switch. 默认情况下,它不收集PasswordLastSet和LastLogonDate -您必须使用
-Properties
开关将特定信息请求为参数。
If I type: 如果输入:
PS> $user.LastLogonDate
PS> $user
It now has the LastLogonDate field but it is $null. 现在,它具有LastLogonDate字段,但它为$ null。 Same goes if I type:
如果输入以下内容,则同样如此:
PS> $user.PasswordLastSet
PS> $user
Both PasswordLastSet and LastLogonDate show in the output for $user
but if I run a condition to see if the value is $null, it returns True
. $user
的输出中都显示了PasswordLastSet和LastLogonDate,但是如果我运行一个条件以查看值是否为$ null,它将返回True
。
Kind of squirrely behavior and I was curious as to why it does that. 有点怪异的行为,我很好奇为什么这样做。 My best educated guess would be that $user is only populated with the default information from the
Get-ADUser
cmdlet and it is very simply WYSIWYG. 我最好的猜测是,$ user仅使用
Get-ADUser
cmdlet的默认信息填充,并且非常简单地为WYSIWYG。 To obtain those particular fields, I have to implicitly request them. 要获取这些特定字段,我必须隐式请求它们。
I wanted to see if certain fields were hidden by default (unless requested in the initial Get-ADUser
cmdlet), so, I typed: 我想查看默认情况下是否隐藏了某些字段(除非在初始
Get-ADUser
cmdlet中要求),所以,我键入了:
PS> $user.random
PS> $user
And sure enough, random :
was a field in there. 可以肯定的是,
random :
那里是一个领域。
I could even go as far as to do this: 我什至可以做到这一点:
PS> $user.random = "Property"
It shows random : {Property}
when I type $user
当我输入
$user
时,它显示为random : {Property}
Question: Can anyone explain briefly why it behaves this way? 问题:有人可以简要解释一下为什么会这样吗?
如果您要测试变量是否具有内容而不是仅仅存在,请尝试:
$user.LastLogonDate.Length -gt 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.