Skip navigation

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

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:12
JohnDoe,11/05/2005,07:10
test,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 off
if \{%1\}==\{\} @echo Syntax: PEReport CSVfile&goto :EOF
setlocal
set csv=%1
if exist %csv% del /q /f %csv%
set days=14
set PE=REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /V PasswordExpiryWarning
for /f "Tokens=1-3" %%a in ('%PE%^|find "REG_DWORD"') do (
 set /a days=%%c
)
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%
set today=%tdyy%%tdmm%%tddd%
for /f "Tokens=*" %%a in ('getusers') do (
 call :userinfo %%a
)
endlocal
goto :EOF
:userinfo
set user=%1
set expires=N
for /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 :EOF
if /i "%expires%" EQU "Never" goto :EOF
call iDateYMD %expires% yy mm dd
Call JSIDateM %yy% %mm% %dd% - %days%
if "%today%" LSS "%AYMD%" goto :EOF
@echo %user%,%expires%,%etime%>>%csv%


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