‎01-13-2014 06:40 PM
‎05-09-2016 04:55 PM
‎01-19-2015 03:33 PM
import-module activedirectory
$maxdays=(Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge.TotalDays
$summarybody="Name `t ExpireDate `t DaysToExpire `t EmailSentTo `n"
(Get-ADUser -SearchBase "OU=Users,DC=DOMAIN,DC=NET" -filter {(Enabled -eq "True") -and (PasswordNeverExpires -eq "False")} -properties *) | Sort-Object pwdLastSet |
foreach-object {
$lastset=Get-Date([System.DateTime]::FromFileTimeUtc($_.pwdLastSet))
$expires=$lastset.AddDays($maxdays).ToShortDateString()
$daystoexpire=[math]::round((New-TimeSpan -Start $(Get-Date) -End $expires).TotalDays)
$samname=$_.samaccountname
$emailTo=$_.mail
if ($emailTo -eq $null)
{
$emailTo="it.department@company.com"
}
$firstname=$_.GivenName
if ($daystoexpire -le 3){
$ThereAreExpiring=$true
$emailFrom = "it.department@company.com"
$subject = "$firstname, your password expires in $daystoexpire day(s)"
$body = "$firstname,
Your password expires in $daystoexpire day(s).
Please press Ctrl + Alt + Del -> Change password. Your new password must have at least: one number, one capital letter, be 8 characters long and not one of your previous 5 passwords.
It is important that this is changed before it expires or you could face problems accessing the corporate network.
Sent to: $emailTo"
$smtpServer = "mailserver.domain"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
$summarybody += "$samname `t $expires `t $daystoexpire `t $emailTo `n"
}
}
if ($ThereAreExpiring) {
$summarybody += " `n Users have been notified :)"
$emailFrom = "it.department@company.com"
$emailTo = "it.department@company.com"
$subject = "Expiring passwords"
$body = $summarybody
$smtpServer = "mailserver.domain"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
$body
}
‎01-14-2014 09:36 AM
‎01-14-2014 04:35 PM
Lansweeper wrote:
Which are the exact features that you are looking for?
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now