Q. How can I generate a CSV file of user logon names that are receiving a password expiration warning?

Jerold Schulman

October 17, 2006

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

I have scripted PEReport.bat to generate a CSV file for all accounts that should be receiving a change password notice., containing User logon name, password expiration date, and password expiration time, like:

JaneDoe,10/26/2006,07:12JohnDoe,11/05/2005,07:10test,08/09/2006,10:56

Where the password expiration date is in your short date format.

The syntax for using PEReport.bat is:

PEReport CSVFile

Where CSVFile is the fully qualified name of the CSV to be generated.

NOTE: PEReport.bat using REG.EXE, built into Windows XP, Windows Server 2003, and later operating systems, or installed from the Windows 2000 Support Tools, and the following batch files, that must be in a the same folder as PEReport.bat, or in a folder that is in your PATH:

GetUsers.bat
JSIDateM.bat
Univdate.bat
Date2JD.bat
JD2Date.bat
iDateYMD.bat

PEReport.bat contains:

@echo offif {%1}=={} @echo Syntax: PEReport CSVfile&goto :EOFsetlocalset csv=%1if exist %csv% del /q /f %csv%set days=14set PE=REG QUERY "HKLMSOFTWAREMicrosoftWindows NTCurrentVersionWinlogon" /V PasswordExpiryWarningfor /f "Tokens=1-3" %%a in ('%PE%^|find "REG_DWORD"') do ( set /a days=%%c)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%set today=%tdyy%%tdmm%%tddd%for /f "Tokens=*" %%a in ('getusers') do ( call :userinfo %%a)endlocalgoto :EOF:userinfoset user=%1set expires=Nfor /f "Tokens=3,4" %%b in ('net user %user% /domain^|findstr /i /c:"Password expires"') do ( set expires=%%b set etime=%%c)if /i "%expires%" EQU "N" @echo PEReport - %user% error.&goto :EOFif /i "%expires%" EQU "Never" goto :EOFcall iDateYMD %expires% yy mm ddCall JSIDateM %yy% %mm% %dd% - %days%if "%today%" LSS "%AYMD%" goto :EOF@echo %user%,%expires%,%etime%>>%csv%


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