我正忙于创建一个查询,该查询将识别密码即将到期的用户。
但是,我在查询中遇到了一个小错误;它似乎返回了正确的结果,但抛出了 5 次错误,这似乎与 5 个用户帐户相对应。
我得到的错误是;
You cannot call a method on a null-valued expression.
At C:\common\SCRIPTS\PASSWORD_EXPIRY_CUSTOM.ps1:9 char:116
+ ... ires | where { $_.PasswordExpires -gt $null -and `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
我可以在它卡住的帐户中看到的唯一区别是它们被设置为在下次登录时更改密码,因此 PasswordExpires 属性实际上是 $null,但即使将其过滤掉似乎也无法修复错误。
我正在运行的代码:
$date = Get-Date
$FirstWarning = $date.AddDays(2).ToShortDateString()
$SecondWarning = $date.AddDays(7).ToShortDateString()
$LastWarning = $date.AddDays(15).ToShortDateString()
$Users = Get-QADUser -SizeLimit 0 -SearchRoot 'mydomain.com/users' -IncludedProperties PasswordExpires |
Where {
$_.PasswordExpires -gt $null -and `
($_.PasswordExpires).ToShortDateString() -eq "$FirstWarning" -or `
($_.PasswordExpires).ToShortDateString() -eq "$SecondWarning" -or `
($_.PasswordExpires).ToShortDateString() -eq "$LastWarning"
}
有人可以帮我吗?我要拔头发了;即使这可能是一个简单的解决方案。