Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password Expire Email Alert

Status
Not open for further replies.

scmoh

Technical User
Aug 28, 2001
59
SG
Hi,

Is there a way to send email alert when AD user's password expire in 15 days via exchange 2010?

Please help.
SC Moh
 
Here's a script that runs on my DC and uses Task Scheduler to run once a week. It attaches a couple of documents about how to change a password and how to choose a good password.

Code:
#This script was written a while back using quest's #AD commandlets those can be 
# downloaded from here:  
#[URL unfurl="true"]http://www.quest.com/powershell/activeroles-server.aspx[/URL] 
#This script will find any AD account in an OU  
#with less than 15 days on its password  
#and send an email to the user 

Add-PSSnapin Quest.ActiveRoles.ADManagement

$tod = get-date 
$cutoff = 16
#Remove the -ou parameter from the command 
#below to get all users in AD 
Get-QADUser -ou 'OU=USERS, DC=domain,DC=local' -enabled -size 0 | where {($_.PasswordNeverExpires -eq $False)} | Foreach-Object { 
    $timeleft = ($_.passwordexpires - $tod).Days  
    $Firstname=$_.givenname 
    $lastname=$_.lastname
    $logonname=$_.SamAccountName
    if ($timeleft -lt $cutoff) { 
        if ($timeleft -lt 1) {$timeleft=0}         
        $body = @" 
Dear $firstname $lastname ($logonname), 

*** YOU PUT YOUR OWN TEXT HERE ***

Thank you, 
Service Desk
My Company
Ph: 123456789
servicedesk@mycompany.com
[URL unfurl="true"]http://mycompany.com[/URL]
"@ 

$User=$_.SamAccountName    
$emailrecipientsTo = $_.PrimarySMTPAddress
$emailrecipientsCC = "servicedesk@mycompany.com"
Send-MailMessage –From servicedesk@mycompany.com –To $emailrecipientsTo –CC $emailrecipientsCC –Subject "ICT ADVISORY: Your Password will expire within the next $timeleft days" –Body $body -Attachment "C:\Scripts\KB_Article_HowToChangeAPassword.pdf", "C:\Scripts\KB_Article_ChoosingAGoodPassword.pdf" –SmtpServer webmail.mycompany.com

    } 
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top