(view source code of getuserdetails.bat as plain text)
@ECHO OFF
IF "%~1"=="" (
cls
echo "Please enter the username you want to check!"
pause
goto _end
)
Set UserToCheck=%~1
echo Getting details for user %UserToCheck%...
rem Getting and saving the userdata to extract all details from this file
NET USER %UserToCheck% /DOMAIN > userinfo.txt
Set Delimiter=!
Set UserName=
Set FullName=
Set Comment=
Set AccountActive=0
Set AccountExpires=
Set PwdLastSet=
Set PwdExpires=
Set PwdChangeable=
Set PwdRequired=
Set UserMayChangePwd=0
Set WrkStatAllowed=
Set LogonScript=
Set UserProfile=
Set HomeDir=
Set LastLogon=
Set LogonHoursAllowed=
rem User name
rem parse userinfo.txt for the string "User name" and store this line in %UserName%
rem to extract just the content, we cut the first 29 characters of the line
FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "User name"') DO SET UserName=%%A
SET UserName=%UserName:~29,100%
rem Full Name
FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Full Name"') DO SET FullName=%%A
SET FullName=%FullName:~29,100%
rem Comment
FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Comment"') DO SET Comment=%%A
SET Comment=%Comment:~29,100%
rem Account active
FIND "Account active Yes" userinfo.txt >NUL
IF NOT ERRORLEVEL 1 set AccountActive=1
rem Account expires
FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Account expires"') DO SET AccountExpires=%%A
SET AccountExpires=%AccountExpires:~29,100%
rem Password last set
FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Password last set"') DO SET PwdLastSet=%%A
SET PwdLastSet=%PwdLastSet:~29,100%
rem Password expires
FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Password expires"') DO SET PwdExpires=%%A
SET PwdExpires=%PwdExpires:~29,100%
rem Password changeable
FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Password changeable"') DO SET PwdChangeable=%%A
SET PwdChangeable=%PwdChangeable:~29,100%
rem Password required
FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Password required"') DO SET PwdRequired=%%A
SET PwdRequired=%PwdRequired:~29,100%
rem User may change password
FIND "User may change password Yes" userinfo.txt >NUL
IF NOT ERRORLEVEL 1 set UserMayChangePwd=1
rem Workstations allowed
FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Workstations allowed"') DO SET WrkStatAllowed=%%A
SET WrkStatAllowed=%WrkStatAllowed:~29,100%
rem Logon script
FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Logon script"') DO SET LogonScript=%%A
SET LogonScript=%LogonScript:~29,100%
rem User profile
FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "User profile"') DO SET UserProfile=%%A
SET UserProfile=%UserProfile:~29,100%
rem Home directory
FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Home directory"') DO SET HomeDir=%%A
SET HomeDir=%HomeDir:~29,100%
rem Last logon
FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Last logon"') DO SET LastLogon=%%A
SET LastLogon=%LastLogon:~29,100%
rem Logon hours allowed
FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Logon hours allowed"') DO SET LogonHoursAllowed=%%A
SET LogonHoursAllowed=%LogonHoursAllowed:~29,100%
rem === Output ===
rem ==============
IF NOT EXIST UserDetailList.txt (
echo UserName %Delimiter% FullName %Delimiter% Comment %Delimiter% AccountActive %Delimiter% AccountExpires %Delimiter% PwdLastSet %Delimiter% PwdExpires %Delimiter% PwdChangeable %Delimiter% PwdRequired %Delimiter% UserMayChangePwd %Delimiter% WrkStatAllowed %Delimiter% LogonScript %Delimiter% UserProfile %Delimiter% HomeDir %Delimiter% LastLogon %Delimiter% LogonHoursAllowed > UserDetailList.txt
)
echo %UserName%%Delimiter%%FullName%%Delimiter%%Comment%%Delimiter%%AccountActive%%Delimiter%%AccountExpires%%Delimiter%%PwdLastSet%%Delimiter%%PwdExpires%%Delimiter%%PwdChangeable%%Delimiter%%PwdRequired%%Delimiter%%UserMayChangePwd%%Delimiter%%WrkStatAllowed%%Delimiter%%LogonScript%%Delimiter%%UserProfile%%Delimiter%%HomeDir%%Delimiter%%LastLogon%%Delimiter%%LogonHoursAllowed% >> UserDetailList.txt
echo done
exit
:_end
page last modified: 2024-04-16; loaded in 0.0062 seconds