# 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. Give values to $smtp,$from,$subject etc and away you go.
# version: 0.1
# type: function
# author: andrewjh
# license: CC0
# x-poshcode-id: 3153
# x-archived: 2012-01-22T04:26:53
# x-published: 2012-01-07T13:49: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 {
#Setup email variables
$smtpserver= "" # Enter your smtp server
$from= "" # Enter your from address
$subject= "" # Enter your email subject
$email= $_.mail
$name= $_.givenName
[string]$body= GetMsgBody
#Execute PowerShell's Send-MailMessage Function
Send-MailMessage -BodyAsHtml:$true -Body $body -To $email -From $from -SmtpServer $smtp -Subject $subject
}