-
Notifications
You must be signed in to change notification settings - Fork 0
/
Email-UserPasswordExpire.ps1
38 lines (36 loc) · 1.72 KB
/
Email-UserPasswordExpire.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Setup Email fields
$SMTP = New-Object Net.Mail.SMTPClient
$SMTP.Host = "MAILSERVER.DOMAIN.LOCAL"
$SMTP.TargetName = "MAILSERVER.DOMAIN.LOCAL"
# CSS Style for Email.
$Style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
$Style = $Style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$Style = $Style + "TH{border: 1px solid black; background: #dddddd; padding: 5px;}"
$Style = $Style + "TD{border: 1px solid black; padding: 5px;}"
$Style = $Style + "</style>"
# All Users
$UserList = Get-QADUser -SizeLimit "100000" -Disabled:$false -SearchRoot "OU=Users - US,DC=DOMAIN,DC=LOCAL" -PasswordNotChangedFor "80"
# DL - Laptop Mobile Users
$UserList | ForEach-Object {
$User = Get-QADUser $_
$PWExpire = $User.PasswordLastSet + ((Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge)
$First = $User.FirstName
$Body = "<hr> Hi $First <br><br>"
$Body += "Your password is going to expire on $PWExpire <br><br>"
$Body += "Please change your password soon to avoid problems accessing Network Resources <br><br>"
$Body += "If you require assistance in changing your password please contact the Help Desk.<br><br>Thank You,<br><br>"
$Body += "Helpdesk <br>"
$Body += "Phone: x999 <br>"
$Body += "Email: <a herf=mailto:[email protected]>[email protected]</a> <br>"
$Body += "Web: <a href=http://helpdesk/>http://HelpDesk/</a> <hr>"
# Start crafting the message.
$Message = New-Object System.Net.Mail.MailMessage $User.Email, $User.Email
$Message.From = "[email protected]"
$Message.ReplyTo = "[email protected]"
$Message.Subject = "Password Expires in 10 days"
$Message.IsBodyHTML = $true
$Message.Priority = "Low"
$Message.Body = ConvertTo-Html -Head $Style -Body $Body
# Send the Message
$SMTP.Send($Message)
}