Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for listadcomputers.bat

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

  1. @ECHO OFF
  2. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  3. ECHO.%* | FIND "/?" >NUL && GOTO Syntax
  4. DSGET.EXE /? >NUL 2>&1   || GOTO Syntax
  5.  
  6. SETLOCAL ENABLEDELAYEDEXPANSION
  7. SET Count=0
  8. IF "%~1"=="" (
  9. 	SET Name=*
  10. 	SET Node=
  11. ) ELSE (
  12. 	SET Name="%~1"
  13. 	IF "%~2"=="" (
  14. 		SET Node=
  15. 	) ELSE (
  16. 		SET Node="%~2"
  17. 	)
  18. )
  19. FOR /F "tokens=2 delims==," %%A IN ('DSQUERY Computer %Node% -name %Name% -limit 10000 ^| SORT') DO (
  20. 	SET /A Count += 1
  21. 	ECHO.%%~A
  22. )
  23. > CON ECHO.
  24. > CON ECHO [%Count% Computers]
  25. ENDLOCAL
  26. GOTO:EOF
  27.  
  28.  
  29. :Syntax
  30. ECHO ListADComputers.bat,  Version 1.00
  31. ECHO List computer objects in Active Directory
  32. ECHO.
  33. ECHO Usage:  LISTADCOMPUTERS  [ filter  [ node ] ]
  34. ECHO.
  35. ECHO Where:  filter   limits the listed computer objects by (part of) their names
  36. ECHO                  (wildcards * allowed)
  37. ECHO         node     is an optional start node in the active directory tree, e.g.
  38. ECHO                  "OU=Management,DC=robvanderwoude,DC=com" (quotes required)
  39. ECHO.
  40. ECHO Written by Rob van der Woude
  41. ECHO http://www.robvanderwoude.com
  42. IF "%OS%"=="Windows_NT" EXIT /B 1
  43.  

page last uploaded: 2017-08-21, 14:26