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


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 off
setlocal
:: set folder path
set pwdnotify=%~f0
set log="%pwdnotify:bat=log%"
call univdate
set /a mm=100%mm%%%100
set /a dd=100%dd%%%100
set /a yy=10000%yy%%%10000
if %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>>&1
endlocal
exit /b 0
:logit
set pwdnotify="%pwdnotify:bat=txt%"
if not exist %pwdnotify% goto error2
for /f "Tokens=*" %%a in ('type %pwdnotify%') do (
 call :userinfo %%a
)
goto :EOF
endlocal
exit /b 0
:userinfo
set days=10
if not \{%3\}

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

\{\} goto error1 set email=%2 set expires=N for /f "Tokens=3" %%b in ('net user %user% /domain^|findstr /i /c:"Password expires"') do ( set expires=%%b ) if /i "%expires%" EQU "N" goto error1 if /i "%expires%" EQU "Never" goto error1 set work=NOTNUMERIC set /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%%%100 set /a dd=100%dd%%%100 set /a yy=10000%yy%%%10000 if %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. endlocal exit /b 2



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish