JSI Tip 7955. How do I e-mail a password expiration notice to selected users?

Jerold Schulman

April 20, 2004

2 Min Read
ITPro Today logo in a gray background | ITPro Today


I have scripted PwdNotify.bat to email selected users that their password is about to expire.

PwdNotify.bat uses a PwdNotify.txt file, in the same folder as PwdNotify.bat, to specify the user, one per line, using the following format:

["]UserName["] ["]UserEMail["] [days]

Where UserName is the NetBIOS user name (SAMID), like Jerry, UserEMail is the user's email address, like [email protected], and days is the number of days prior to password expiration that you want to start sending the email. If not specified, days will default to 10.

PwdNotify.bat generates a PwdNotify.log file, in the same folder, that contains the disposition of the job, and each user.

PwdNotify.bat uses the following files, which must be in your path:

JSIDateM.bat
Univdate.bat
Date2JD.bat
JD2Date.bat
Blat.exe

I recommend scheduling PwdNotify.bat, using a Domain Admins account whose password never expires, and that never logs on, so it will run in the background, such as [email protected]. I use Scheduled Tasks to run PwdNotify.bat every day, at 00:01, on the PDC emulator.

PwdNotify.bat contains:

@echo offsetlocal:: set folder pathset pwdnotify=%~f0set log="%pwdnotify:bat=log%"call univdateset /a mm=100%mm%%%100set /a dd=100%dd%%%100set /a yy=10000%yy%%%10000if %yy% LSS 10 set /a yy=200%yy%if %yy% LSS 100 set /a yy=20%yy%if %mm% LSS 10 set mm=0%mm%if %dd% LSS 10 set dd=0%dd%set tdyy=%yy%set tdmm=%mm%set tddd=%dd%@echo %tdyy% %tdmm% %tddd%>%log%set today=%tdyy%%tdmm%%tddd%call :logit>>%log% 2>>&1endlocalexit /b 0:logitset pwdnotify="%pwdnotify:bat=txt%"if not exist %pwdnotify% goto error2for /f "Tokens=*" %%a in ('type %pwdnotify%') do ( call :userinfo %%a)goto :EOFendlocalexit /b 0:userinfoset days=10if not {%3}

{} set days=%3set /a days=1000%days%%%1000set user=%1if {%2}

{} goto error1set email=%2set expires=Nfor /f "Tokens=3" %%b in ('net user %user% /domain^|findstr /i /c:"Password expires"') do ( set expires=%%b)if /i "%expires%" EQU "N" goto error1if /i "%expires%" EQU "Never" goto error1set work=NOTNUMERICset /a work=%days%if "%work%" NEQ "%days%" goto error1:: The following is for MM/DD/YY date format. If net user returns DD/MM/YY, or DD-MM-YY,:: then set dd=%%x and set mm=%%y.for /f "Tokens=1-3 Delims=/-" %%x in ('@echo %expires%') do ( set mm=%%x set dd=%%y set yy=%%z)set /a mm=100%mm%%%100set /a dd=100%dd%%%100set /a yy=10000%yy%%%10000if %yy% LSS 10 set /a yy=200%yy%if %yy% LSS 100 set /a yy=20%yy%if %mm% LSS 10 set mm=0%mm%if %dd% LSS 10 set dd=0%dd%Call JSIDateM %yy% %mm% %dd% - %days%@echo %user% %email% %yy%%mm%%dd% %days% %AYMD%if "%today%" LSS "%AYMD%" goto :EOF@echo The %USERDNSDOMAIN% domain password for user %user% expires on %expires%. Please change your domain password.>"%temp%PwdNotify.tmp"blat "%temp%PwdNotify.tmp" -to %email% -s "The %USERDNSDOMAIN% domain password for user '%user%' expires on %expires%."goto :EOF:error1@echo PwdNotify - Syntax - %1 %2 %3 user not found, password never expires, or info missing or incorrect.goto :EOF:error2@echo PwdNotify - File %pwdnotify% not found.endlocalexit /b 2



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like