(view source code of memberof.bat as plain text)
@ECHO OFF
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
IF "%~1"=="" GOTO Syntax
IF NOT "%~2"=="" IF /I NOT "%~2"=="/R" GOTO Syntax
SETLOCAL ENABLEDELAYEDEXPANSION
:: Check both availability of DSQUERY and validity of command line argument
DSQUERY.EXE User -samid %1 2>NUL | FIND.EXE "=" >NUL || GOTO Syntax
:: Recursive or not?
IF /I "%~2"=="/R" (SET Expand=-expand) ELSE (SET Expand=)
FOR /F "tokens=*" %%A IN ('DSQUERY.EXE User -samid "%~1"') DO (
ECHO.
FOR /F "skip=1 tokens=*" %%B IN ('ECHO.%%A ^| DSGET.EXE User -samid ^| FINDSTR.EXE /R /B /C:" "') DO SET SAMID=%%B
FOR /L %%B IN (1,1,16) DO (IF "!SAMID:~-1!"==" " SET SAMID=!SAMID:~0,-1!)
FOR /F "skip=1 tokens=*" %%B IN ('ECHO.%%A ^| DSGET.EXE User -display ^| FINDSTR.EXE /R /B /C:" "') DO SET Display=%%B
FOR /L %%B IN (1,1,16) DO (IF "!Display:~-1!"==" " SET Display=!Display:~0,-1!)
ECHO !SAMID! ^(!Display!^)
ECHO.%%A | DSGET.EXE User -memberof %Expand% | DSGET.EXE Group -samid | MORE +1 | SORT.EXE | FINDSTR.EXE /R /B /C:" "
)
ENDLOCAL
GOTO:EOF
:Syntax
ECHO.
ECHO MemberOf.bat, Version 2.01 for Windows 2000 and later
ECHO (Recursively) list all groups of which the specified user is a member.
ECHO.
ECHO Usage: MEMBEROF user_id [/R]
ECHO.
ECHO Where: "user_id" is/are the (SAM) user account name(s) to be queried
ECHO /R lists groups recursively
ECHO.
ECHO Note: This batch file uses DSGET and DSQUERY (native in Windows
ECHO Server 2003, will work in Windows 2000 and XP if available).
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
page last modified: 2024-04-16; loaded in 0.0056 seconds