Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for getuserdetails.bat

(view source code of getuserdetails.bat as plain text)

  1. @ECHO OFF
  2.  
  3. IF "%~1"=="" (
  4. 	cls
  5. 	echo "Please enter the username you want to check!"
  6. 	pause
  7. 	goto _end	
  8. )
  9.  
  10. Set UserToCheck=%~1
  11.  
  12.  
  13. echo Getting details for user %UserToCheck%...
  14.  
  15. rem Getting and saving the userdata to extract all details from this file
  16. NET USER %UserToCheck% /DOMAIN > userinfo.txt
  17.  
  18. Set Delimiter=!
  19.  
  20. Set UserName=
  21. Set FullName=
  22. Set Comment=
  23. Set AccountActive=0
  24. Set AccountExpires=
  25. Set PwdLastSet=
  26. Set PwdExpires=
  27. Set PwdChangeable=
  28. Set PwdRequired=
  29. Set UserMayChangePwd=0
  30. Set WrkStatAllowed=
  31. Set LogonScript=
  32. Set UserProfile=
  33. Set HomeDir=
  34. Set LastLogon=
  35. Set LogonHoursAllowed=
  36.  
  37. rem User name
  38. rem parse userinfo.txt for the string "User name" and store this line in %UserName% 
  39. rem to extract just the content, we cut the first 29 characters of the line
  40. FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "User name"') DO SET UserName=%%A
  41. SET UserName=%UserName:~29,100%
  42.  
  43. rem Full Name
  44. FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Full Name"') DO SET FullName=%%A
  45. SET FullName=%FullName:~29,100%
  46.  
  47. rem Comment
  48. FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Comment"') DO SET Comment=%%A
  49. SET Comment=%Comment:~29,100%
  50.  
  51. rem Account active
  52. FIND "Account active               Yes" userinfo.txt >NUL
  53. IF NOT ERRORLEVEL 1 set AccountActive=1
  54.  
  55. rem Account expires
  56. FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Account expires"') DO SET AccountExpires=%%A
  57. SET AccountExpires=%AccountExpires:~29,100%
  58.  
  59.  
  60.  
  61. rem Password last set
  62. FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Password last set"') DO SET PwdLastSet=%%A
  63. SET PwdLastSet=%PwdLastSet:~29,100%
  64.  
  65. rem Password expires
  66. FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Password expires"') DO SET PwdExpires=%%A
  67. SET PwdExpires=%PwdExpires:~29,100%
  68.  
  69. rem Password changeable
  70. FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Password changeable"') DO SET PwdChangeable=%%A
  71. SET PwdChangeable=%PwdChangeable:~29,100%
  72.  
  73. rem Password required
  74. FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Password required"') DO SET PwdRequired=%%A
  75. SET PwdRequired=%PwdRequired:~29,100%
  76.  
  77. rem User may change password
  78. FIND "User may change password     Yes" userinfo.txt >NUL
  79. IF NOT ERRORLEVEL 1 set UserMayChangePwd=1
  80.  
  81.  
  82.  
  83. rem Workstations allowed
  84. FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Workstations allowed"') DO SET WrkStatAllowed=%%A
  85. SET WrkStatAllowed=%WrkStatAllowed:~29,100%
  86.  
  87. rem Logon script
  88. FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Logon script"') DO SET LogonScript=%%A
  89. SET LogonScript=%LogonScript:~29,100%
  90.  
  91. rem User profile
  92. FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "User profile"') DO SET UserProfile=%%A
  93. SET UserProfile=%UserProfile:~29,100%
  94.  
  95. rem Home directory
  96. FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Home directory"') DO SET HomeDir=%%A
  97. SET HomeDir=%HomeDir:~29,100%
  98.  
  99. rem Last logon
  100. FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Last logon"') DO SET LastLogon=%%A
  101. SET LastLogon=%LastLogon:~29,100%
  102.  
  103.  
  104.  
  105. rem Logon hours allowed
  106. FOR /F "delims=" %%A IN ('type userinfo.txt ^| FIND "Logon hours allowed"') DO SET LogonHoursAllowed=%%A
  107. SET LogonHoursAllowed=%LogonHoursAllowed:~29,100%
  108.  
  109.  
  110.  
  111. rem === Output ===
  112. rem ==============
  113. IF NOT EXIST UserDetailList.txt (
  114.   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
  115. )
  116.  
  117. 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
  118.  
  119. echo done
  120. exit
  121.  
  122. :_end
  123.  

page last modified: 2024-04-16; loaded in 0.0210 seconds