š Free Script: AD Password Expiry Notifier (PowerShell)
Every helpdesk team deals with this: users call in because their password expired and they didn't know it was coming. This script checks Active Directory and emails users 7, 3, and 1 day before expiry.
Set it as a scheduled task and watch password reset tickets drop.
---
The Script
# AD Password Expiry Notifier
# Run as scheduled task daily at 8 AM
Import-Module ActiveDirectory
$SmtpServer = "smtp.yourdomain.com"
$FromAddress = "it-notifications@yourdomain.com"
$WarningDays = @(7, 3, 1)
$MaxPasswordAge = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge.Days
$Users = Get-ADUser -Filter {
Enabled -eq $true -and
PasswordNeverExpires -eq $false
} -Properties Mail, PasswordLastSet, DisplayName
foreach ($User in $Users) {
if (-not $User.Mail -or -not $User.PasswordLastSet) { continue }
$ExpiryDate = $User.PasswordLastSet.AddDays($MaxPasswordAge)
$DaysLeft = ($ExpiryDate - (Get-Date)).Days
if ($DaysLeft -in $WarningDays) {
$Subject = "ā ļø Your password expires in $DaysLeft day(s)"
$Body = @"
Hi $($User.DisplayName),
Your network password will expire on $($ExpiryDate.ToString('dddd, MMMM dd, yyyy')).
To change it:
1. Press Ctrl + Alt + Delete
2. Click 'Change a password'
3. Enter your current password and choose a new one
If you're remote, connect to VPN first.
Questions? Contact the helpdesk.
- IT Team
"@
Send-MailMessage -To $User.Mail -From $FromAddress `
-Subject $Subject -Body $Body -SmtpServer $SmtpServer
Write-Host "Notified: $($User.DisplayName) ā $DaysLeft days left"
}
}
Write-Host "Done. Password expiry check complete."---
Setup
Save as
PasswordExpiryNotifier.ps1Update
$SmtpServerand$FromAddresswith your mail settingsCreate a Windows Scheduled Task to run daily at 8 AM
Run as a service account with AD read permissions
---
This is the kind of automation that saves hours and makes you look like a hero to your team. More free scripts coming ā follow this page.
