Advertisement
Guest User

Untitled

a guest
May 6th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. Import-Module ActiveDirectory
  2. $below = (Get-Date).AddDays(-77)
  3. $above = (Get-Date).AddDays(-76)
  4. $Persons = Get-ADUser -Filter {PasswordNeverExpires -eq $False -AND (PasswordLastSet -lt $above -AND PasswordLastSet -gt $below) -AND (LastLogonDate -like "*") -AND (MAil -like "*")}
  5.  
  6. foreach ($Person IN $Persons) {
  7. $body = "Your Windows password will expire in 14 days. Please consider changing your password. - $User.Name - $User.PasswordLastSet"
  8. Send-MailMessage -To $User.Mail -Subject "Alert! Password Expiring Soon!" -From 'Do_Not_Reply@domain.com' -Body $body -SmtpServer smtp.server.com
  9. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement