PoshCode Archive  Artifact [9d357a544b]

Artifact 9d357a544bc3124741ed2cf03b1b00e20e0c0498f598e82b02c07f9354468920:

  • File Email-ExpiringADAccounts.ps1 — part of check-in [61bd214f3e] at 2018-06-10 13:20:56 on branch trunk — 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. (user: andrewjh size: 1258)

# 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"
	}