[英]Get-ADUser AccountExpirationDate
I am having some difficulties with the output of the Account Expiration Date from some users in our AD.我在我们 AD 中的某些用户的帐户到期日期的 output 上遇到了一些困难。
This is the code I am using:这是我正在使用的代码:
Get-ADUser -Properties AccountExpirationDate
Problem is when I have a user in AD that has not set a expiration date it shows blank.问题是当我在 AD 中有一个用户没有设置到期日期时,它显示为空白。 I want that it shows 'Never Expires' because that is the case.
我希望它显示“永不过期”,因为情况就是如此。 When I check a user with expiration date it will show me the exact expiry date.
当我检查具有到期日期的用户时,它会向我显示确切的到期日期。
I also tried with if else statement, but no luck so far.我也尝试了 if else 语句,但到目前为止还没有运气。
Thanks in advance.提前致谢。
Regards, Ralph问候, 拉尔夫
Test if the value is $null
:测试该值是否为
$null
:
$user = Get-ADUser $username -Properties AccountExpirationDate |Select SAMAccountName,@{Name='AccountExpiration'; Expression={if($null -eq $_.AccountExpirationDate){'Never Expires'}else{$_.AccountExpirationDate}}}
Another way could be to also ask for the LDAP accountExpires
property, which is a numeric value.另一种方法可能是要求 LDAP
accountExpires
属性,它是一个数值。
If that user property equals to 0 or 9223372036854775807, then the account never expires.如果该用户属性等于 0 或 9223372036854775807,则该帐户永不过期。
Get-ADUser -Properties AccountExpirationDate, accountExpires |
Select-Object Name, DistinguishedName,
@{Name = 'AccountExpirationDate'
Expression = {
if ($_.accountExpires -gt 0 -and $_.accountExpires -ne 9223372036854775807) { $_.AccountExpirationDate }
else { 'Never Expires' }
}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.