Skip navigation

JSI Tip 8075. How can I email a warning to a user that their domain account is going to expire?

If you have set some domain accounts to expire, you might want to warn the user prior to the actual expiration date.

NOTE: This is for account expiration, NOT password expiration.

I have scripted AEWarn.bat to produce the required email. The syntax for using AEWarn.bat is:

AEWarn \[days\] \[EmailDomain\]

where days is an optional parameter that specifies the number number of days prior to the expiration that the warning is produced. The default is 14 days. EmailDomain is an optional parameter that specifies the email domain to use, as in UserName@EmailDomain. The default is %UserDNSDomain% of the account that is running the AEWarn.bat script.

You can schedule AEWarn.bat to run daily, or you can run it manually.

AEWarn.bat uses the following routines, which must be in a folder in your PATH:

     GetUsers.bat
     univdate.bat 
     JSIDateM.bat
     Date2JD.bat
     JD2Date.bat
     BLAT.exe

AEWarn.bat contains:

@echo off
setlocal
set /a warn=14
if not \{%1\}

\{\} set /a warn=%1 set email=%UserDNSDomain% if not \{%2\}

\{\} set email=%2 call univdate call jsidatem %yy% %mm% %dd% + %warn% for /f "Tokens=*" %%u in ('getusers') do ( set user=%%u call :chkdt ) if exist "%TEMP%\aewarn.txt" del /q "%TEMP%\aewarn.txt" endlocal goto :EOF :chkdt for /f "Tokens=3" %%a in ('net user "%user%" /domain^|findstr /i /L /c:"Account expires"') do ( set expires=%%a ) if /i "%expires%" EQU "Never" goto :EOF for /f "Tokens=1-3 Delims=/" %%m in ('@echo %expires%') do ( set mm=%%m set dd=%%n set yy=%%o ) set /a yy=10000%yy%%%10000 set /a mm=100%mm%%%100 set /a dd=100%dd%%%100 if %yy% LSS 10 set yy=200%yy% if %yy% LSS 100 set yy=20%yy% if %mm% LSS 10 set mm=0%mm% if %dd% LSS 10 set dd=0%dd% if "%AYMD%" LSS "%yy%%mm%%dd%" goto :EOF @echo %user%: Your account expires on %expires%.>"%TEMP%\aewarn.txt" blat "%TEMP%\aewarn.txt" -to %user%@%email% -s "%user%: Your account expires on %expires%"



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