Recently there was a requirement to monitor service accounts expiration, as in our environment every service account is configured for expiry & if it is missed than it can cause issues with Critical Applications.
This script will monitor accounts mentioned in csv file & send email alerts to corresponding email before 15 days account expiry date is reached.
extract the zip file, Change the below variables at the beginning of the script, update the csv file with the accounts that you want to monitor and schedule the batch file thru task scheduler.
$smtpserver = "smtpserver"
$from = "AccountExpiry@labtest.com"
$days = "-15" ---This is the number of days before you want the reminder email to be sent
$errormail = "firstname.lastname@example.org" (if script resulted in some sort of error than it should be reported to some email)
download Quest Management Shell (its a free shell) --> http://www.quest.com/powershell/activeroles-server.aspx
Note:- Quest Management Shell is required for this script to work.