#* PROPERTY OF BRANT PUTTKAMMER, PLEASE CONTACT ME IF YOU HAVE QUESTIONS #* PLEASE USE CAUTION WHEN RUNNING THIS PROGRAM ON YOUR SYSTEM import-module ActiveDirectory; $maxPasswordAgeTimeSpan = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge Get-ADUser -filter * -properties PasswordLastSet, PasswordExpired, PasswordNeverExpires, EmailAddress, GivenName, SamAccountName | foreach { $today=get-date $UserName=$_.GivenName $Email=$_.EmailAddress $DisplayName=$_.SamAccountName if (!$_.PasswordExpired -and !$_.PasswordNeverExpires) { $ExpiryDate=$_.PasswordLastSet + $maxPasswordAgeTimeSpan $DaysLeft=($ExpiryDate-$today).days if ($DaysLeft -eq 1){ $DayText = "day" } elseif ($DaysLeft -eq 0) { $DayText = "days (less than 24 hours - change your password now!)" } else { $DayText = "days" } if ($DaysLeft -lt 7 -and $DaysLeft -ge 0){ $WarnMsg = "
This is a friendly reminder $UserName,
Your Windows Password will expire in $DaysLeft $DayText or exactly on $ExpiryDate!
To change the password, please follow the steps listed below:
* If you change your Windows Password during the day, email may be unavailable for 15 minutes. There is a sync delay between services. Simply close Outlook and then reopen after 15 minutes.
If you have any questions about changing the password, please see your immediate supervisor.
- System Administrators
" ForEach ($email in $_.EmailAddress) { send-mailmessage -to $email -from 'distribution-group@domain.com' -cc user@domain.com -bcc user2@domain.com -Subject "Password Reminder: Your Windows Password will expire in $DaysLeft $DayText!" -body $WarnMsg -smtpserver 192.168.0.0 -BodyAsHtml } } } }