# encoding: ascii
# api: powershell
# title: Email-ExpiringADAccounts
# description: Quick and simple, send an email to AD accounts expiring before a specified date. The $body is specific to my org needs, but simply customize this to suit.
# version: 0.1
# type: function
# author: andrewjh
# license: CC0
# x-poshcode-id: 3140
# x-archived: 2012-02-05T04:25:06
# x-published: 2012-01-03T16:36:00
#
#
Function GetMsgBody {
Write-Output @"
<p>Dear $name,</p>
Your ABC network account is about to expire.<br/>
Please email helpdesk@abc.com or simply hit 'reply', and include the following details to have your account extended.<br/>
<br/>
Your name:<br/>
The department you currently volunteer in:<br/>
The staff supervisor's name you currently report to:<br/>
The current status of your involvement with ABC (Staff/Student/Volunteer):<br/>
<br/>
Kind Regards,<br/>
ABC IT Services
"@
}
Get-QADUser -AccountExpiresBefore "31/01/2012" -Enabled -SizeLimit 0 | ForEach-Object {
$email = $_.mail
$name = $_.givenName
[string]$body = GetMsgBody
Send-MailMessage -BodyAsHtml:$true -Body $body -To $email -From 'helpdesk@abc.com' -SmtpServer 'smtp.abc.com' -Subject "Your account is about to expire"
}