Skip to content

Instantly share code, notes, and snippets.

@TheRealNoob
Created March 30, 2017 04:38
Show Gist options
  • Save TheRealNoob/0a7140239034791528fc667dfc995dbb to your computer and use it in GitHub Desktop.
Save TheRealNoob/0a7140239034791528fc667dfc995dbb to your computer and use it in GitHub Desktop.
<#
CSV CONTENT
Display Name,SAM Account Name,Password Last Set,Password Expiry Date,E-mail Address,Password expires in
FakeNam1,FakeUsername1,Blah1,123,[email protected],4 day(s)
FakeNam2,FakeUsername2,Blah2,456,[email protected],3 day(s)
#>
<#PROCESS
* Import CSV into UserList
* For each user
** Email user
#>
#VARIABLES
$ReportLocation = "\FILEPATH\Soon_to_expire User Password...TEST.csv"
$From = "Service.Desk@ORG"
$Subject = "Password Expires In 4 Days"
$SMTPServer = "CantShareThat.com"
$Body = "<font face='arial'><p>Please be advised that account <font color='red'><b>$($person."SAM Account Name")</b></font> will expire on <font color='red'><b>$($person."Password Expiry Date")</b></font>.
</p><p>Refer to <b><a href=`"https://URL/kb_view.do?sysparm_article=KB0012633`">How do I reset my password?</a></b> for assistance.</p>
<p>Regards,</p><p>Service Desk</p></font>"
$list = import-csv $ReportLocation
Foreach ($person in $list) {
If ($person."password expires in" -le 4) {
$Subject = "Password Expires In $($person."password expires in") Days"
$Body = "<font face='arial'><p>Please be advised that account <font color='red'><b>$($person."SAM Account Name")</b></font> will expire on <font color='red'><b>$($person."Password Expiry Date")</b></font>.
</p><p>Refer to <b><a href=`"https://URL/kb_view.do?sysparm_article=KB0012633`">How do I reset my password?</a></b> for assistance.</p>
<p>Regards,</p><p>Service Desk</p></font>"
Send-MailMessage -To $person."E-Mail Address" `
-Subject $Subject `
-From $From `
-Body $Body -BodyAsHtml `
-SmtpServer $SMTPServer
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment