Re:关于邮件帐号即将到期,系统自动发一封邮件要求更改密码的 ..
更改密码会改变WhenChanged的值,
可以每隔一天执行以下脚本
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
$NewUsers = Get-User -ResultSize Unlimited | Where {($_.WhenChanged -gt (get-date).adddays(密码更新周期(天)))}
foreach ($NewUser in $NewUsers)
{
$SmtpClient = new-object system.net.mail.smtpClient
$MailMessage = New-Object system.net.mail.mailmessage
$SmtpClient.Host = "HubTRole.domain.com"
$mailmessage.from = ("
Admin@domain.com")
$Recipient = (Get-Recipient $NewUser.identity).PrimarySMTPAddress
$mailmessage.To.add($Recipient)
$mailmessage.Subject = “Message Subject”
$mailmessage.Body = “Type Body Here...”
$smtpclient.Send($mailmessage)
}
--------------------------------------------------------------------------------
这个脚本的问题在于比如说他前一次改密码是在密码到期前5天,那他下次收到改密码提醒(也就是这封信)也是在密码到期前的第五天。