(view source code of grmember.bat as plain text)
@ECHO OFF
:: Use local variables
IF "%OS%"=="Windows_NT" SETLOCAL
:: Check Windows version
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
:: Check number of command line arguments and validity of optional switch
IF "%~1"=="" GOTO Syntax
IF NOT "%~2"=="" IF /I NOT "%~2"=="/B" IF /I NOT "%~2"=="/G" IF /I NOT "%~2"=="/U" IF /I NOT "%~2"=="/V" GOTO Syntax
:: Reset variables
SET Descri=
SET Member=
SET Prefix=
:: Interpret the optional switch's value
IF /I "%~2"=="/G" (SET ListU=0) ELSE (SET ListU=1)
IF /I "%~2"=="/U" (SET ListG=0) ELSE (SET ListG=1)
:: Run a query to check availability of DSQUERY and validity of the specified group
DSQUERY.EXE Group -name "%~1" -limit 2 2>NUL | FIND.EXE "=" >NUL
IF ERRORLEVEL 1 GOTO Syntax
:: One command for users and one for nested groups, commands grouped before sorting
(
IF "%ListG%"=="1" FOR /F "tokens=1*" %%A IN ('DSQUERY.EXE Group -samid "%~1" -limit 10000 2^>NUL ^| DSGET.EXE Group -members 2^>NUL ^| DSGET.EXE Group -samid -desc 2^>NUL ^| FINDSTR.EXE /R /B /I /V /C:" desc " ') DO CALL :Display %%B %%A *
IF "%ListU%"=="1" FOR /F "tokens=1*" %%A IN ('DSQUERY.EXE Group -samid "%~1" -limit 10000 2^>NUL ^| DSGET.EXE Group -members 2^>NUL ^| DSGET.EXE User -samid -display 2^>NUL ^| FINDSTR.EXE /R /B /I /V /C:" samid "') DO CALL :Display %%A %%B
) | FINDSTR.EXE /R /B /I /V /C:"dsget succeeded" | SORT.EXE
:: Done
ENDLOCAL
GOTO:EOF
:Display
SETLOCAL
:: Append 20 spaces after first 2 argument values
SET Member=%1
SET Descri=%2
:: Then truncate arguments at 20 characters
SET Member=%Member:~0,20%
SET Descri=%Descri:~0,20%
:: Default prefix is a space
IF "%~3"=="" (SET Prefix= ) ELSE (SET Prefix=%~3)
:: Display result in 2 columns
ECHO %Prefix%%Member%%Descri%
GOTO:EOF
:Syntax
ECHO.
ECHO GrMember.bat, Version 0.53 BETA for Windows 2000 / XP / Server 2003
ECHO List all members of the specified group(s), users as well as nested groups.
ECHO.
:: Pipe symbols cannot be ECHOed in Windows 9x, so in that case
:: we need to use an alternative character (like ASCII 179)
IF "%OS%"=="Windows_NT" ECHO Usage: GRMEMBER group_name [ /B ^| /G ^| /U ^| /V ]
IF NOT "%OS%"=="Windows_NT" ECHO Usage: GRMEMBER group_name [ /B ³ /G ³ /U ³ /V ]
ECHO.
ECHO Where: "group_name" is the name of the group to be queried
ECHO /B lists both users and groups (default)
ECHO /G lists groups only
ECHO /U lists users only
ECHO /V lists both users and groups, same as /B
ECHO.
ECHO Notes: Nested groups are marked by an asterisk.
ECHO This batch file uses DSGET and DSQUERY (native in Windows
ECHO Server 2003, will work in Windows 2000 and XP if available).
ECHO Increase DSQUERY's "-limit" value for networks where groups
ECHO may contain over 10000 members.
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
:: Discard of local variables
IF "%OS%"=="Windows_NT" ENDLOCAL
page last modified: 2024-04-16; loaded in 0.0077 seconds