广告密码中的聚会错误到期提醒
这是代码的一部分,该代码如果用户的Active Directory密码即将到期。
它曾经起作用,但是现在我突然收到了这个错误!也许是因为当地的机器语言是德语的德语日期格式,但我不知道要修复它!我真的很感谢您的帮助。
代码:
#Calculate expirering passwords and store them in an object
$today = (get-date).date
[Threading.Thread]::CurrentThread.CurrentUICulture = 'en-US';
$ExpirePasswordList =
foreach ($ADUser in $AllADUsers) {
$PasswordLastSet = $ADUser.PasswordLastSet
$PasswordExpireDate = (get-date $PasswordLastSet).AddDays($MaxPasswordAge)
$DaysBeforePasswordchange = (New-TimeSpan -start $today -end $PasswordExpireDate).days
if ($DaysBeforePasswordchange -le $WarningLevel) {
[pscustomobject]@{
Givenname = $ADUser.GivenName
Surname = $ADUser.Surname
MailAddress = $ADUser.mail
DaysBeforePasswordchange = $DaysBeforePasswordchange
PasswordExpireDate = $PasswordExpireDate
}
}
}
错误:
Get-Date : Cannot bind parameter 'Date' to the target. Exception setting "Date": "Cannot convert null to type "System.DateTime"."
At line:6 char:43
+ $PasswordExpireDate = (get-date $PasswordLastSet).AddDays($ ...
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Get-Date], ParameterBindingException
+ FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.GetDateCommand
this is part of a code that reminds users if their active directory password is about to expire.
It used to work, but now I get this error out of a sudden! Maybe because the Local Machine Language is German with German Date Format, but I don't know hot to fix it! I would really appreciate the help.
The Code:
#Calculate expirering passwords and store them in an object
$today = (get-date).date
[Threading.Thread]::CurrentThread.CurrentUICulture = 'en-US';
$ExpirePasswordList =
foreach ($ADUser in $AllADUsers) {
$PasswordLastSet = $ADUser.PasswordLastSet
$PasswordExpireDate = (get-date $PasswordLastSet).AddDays($MaxPasswordAge)
$DaysBeforePasswordchange = (New-TimeSpan -start $today -end $PasswordExpireDate).days
if ($DaysBeforePasswordchange -le $WarningLevel) {
[pscustomobject]@{
Givenname = $ADUser.GivenName
Surname = $ADUser.Surname
MailAddress = $ADUser.mail
DaysBeforePasswordchange = $DaysBeforePasswordchange
PasswordExpireDate = $PasswordExpireDate
}
}
}
The Error:
Get-Date : Cannot bind parameter 'Date' to the target. Exception setting "Date": "Cannot convert null to type "System.DateTime"."
At line:6 char:43
+ $PasswordExpireDate = (get-date $PasswordLastSet).AddDays($ ...
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Get-Date], ParameterBindingException
+ FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.GetDateCommand
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 theo 所建议的那样正确
$ passwordlastset
结果是null
beacuse beacuse您未提及password> passwordlastset < /code>属性在其 -
属性
get -aduser
的参数中,并插入变量$ alladusers
。尝试以下PowerShell代码,它应该为您工作。
参考: https://social.technet.microsoft.com/wiki/wiki/wiki/contents/32912.powershell-get-get-get-aDuser-to-Aduser-to-Aduser-to-aduser-最后一式和兴奋的信息
As Suggested by Theo is correct
$PasswordLastSet
outcome isnull
beacuse you didn't mentionedPasswordLastSet
attribute in its -Properties
parameter ofGet-ADUser
and taking into variable$AllADUsers
.Try with below powershell code it should work for you.
Reference : https://social.technet.microsoft.com/wiki/contents/articles/32912.powershell-get-aduser-to-see-password-last-set-and-expiry-information-and-more.aspx