1

嗨,我有以下脚本,它通过电子邮件向密码将在 $daysleftonpwd 中过期的用户发送电子邮件,但不确定如何添加“仅当用户的密码设置为过期”这意味着我不想通过电子邮件向密码已设置的用户发送电子邮件下次到期。

Get-QADGroupMember -Identity TEAM_GROUP | % {
$name = $_.Name
$email = $_.Email
$daysleftonpwd = ((Get-QADUser -SizeLimit 0 -SearchRoot $OU -Identity $_.SamAccountName | select PasswordExpires).PasswordExpires - $date | select Days).Days
if (((Get-QADUser -Identity $_.SamAccountName | select PasswordExpires).PasswordExpires - $date).Days -lt $threshold){

    Write-Host "$Name would be emailed using $email because password is less than $threshold"
    $y = $y + "<br>$name</br>"
    mailuser
}

有任何想法吗?

4

1 回答 1

1

Get-QADUser 返回的字段之一是 PasswordNeverExpires:

PS C:\> ( Get-QADUser regularuser ).PasswordNeverExpires
False
PS C:\> ( Get-QADUser specialuser ).PasswordNeverExpires
True

应该很容易在你的脚本中使用它来测试。还有其他方法可以直接检查(您必须同时查看 UserAccountControl - https://msdn.microsoft.com/en-us/library/ms680832%28v=vs.85%29.aspx和 msDS-User-Account -Control-Computed - https://msdn.microsoft.com/en-us/library/ms677840%28v=vs.85%29.aspx),但这有点难看......

于 2016-06-08T20:57:15.990 回答