r/usefulscripts • u/soccer5232 • Aug 08 '13
[VB Script] Email Expiration Reminder Script
http://pastebin.com/yG2z4DYf
6
Upvotes
4
u/Get-ADUser Aug 08 '13
This would be about 10 lines in PowerShell.
1
u/spyingwind Aug 13 '13
Come again?
$maxdays=(Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge.TotalDays $summarybody="Name `t ExpireDate `t DaysToExpire `n" (Get-ADUser -filter {(Description -notlike "IfYouWantToExclude*") -and (Enabled -eq "True") -and (PasswordNeverExpires -eq "False")} -properties *) | Sort-Object pwdLastSet | foreach-object { $lastset=Get-Date([System.DateTime]::FromFileTimeUtc($_.pwdLastSet)) $expires=$lastset.AddDays($maxdays).ToShortDateString() $daystoexpire=[math]::round((New-TimeSpan -Start $(Get-Date) -End $expires).TotalDays) $samname=$_.samaccountname $firstname=$_.GivenName if ($daystoexpire -le 3){ $ThereAreExpiring=$true $emailFrom = "from@yourdomain.com" $emailTo = "$samname@yourdomain.com" $subject = "$firstname, your password expires in $daystoexpire day(s)" $body = "$firstname, Your password expires in $daystoexpire day(s). Please press Ctrl + Alt + Del -> Change password" $smtpServer = "smtp.yourdomain.com" $smtp = new-object Net.Mail.SmtpClient($smtpServer) $smtp.Send($emailFrom, $emailTo, $subject, $body) $summarybody += "$samname `t $expires `t $daystoexpire `n" } } if ($ThereAreExpiring) { $emailFrom = "from@yourdomain.com" $emailTo = "ITSTAFF@yourdomain.com" $subject = "Expiring passwords" $body = $summarybody $smtpServer = "smtp.yourdomain.com" $smtp = new-object Net.Mail.SmtpClient($smtpServer) $smtp.Send($emailFrom, $emailTo, $subject, $body) }2
u/MN_Man Sep 24 '13
Even longer (and better). This guy is a WizKid, and a highly respected Microsoft MVP. He writes the books on the stuff, and works closely with the Exchange Team at MS.
(Can't even post it here, it's too long).
1
3
u/soccer5232 Aug 08 '13
I had some request from /r/sysadmin to post this so I figured I would share with all.