JSI Tip 0748. Run a Group/User or User/Group report.
October 2, 1998
Using the public domain SHOWMBRS program and standard commands, you can generate a CSV (Comma Seperated Value) file that contains GroupName and UserName. The format of the file is:
"GroupName","AccountBaseUserName" where AccountBase is either a Domain Name or a Computer Name.
- If you run the report on a Domain Controller and include the Domain Name parameter, AccountBase will be the Domain Name.
- If you run the report on a Domain Controller and do not include the Domain Name parameter,
AccountBase will be null for Domain Global Group membership.
- If you run it on a server or a workstation, GroupName will be local and AccountBase will indicate
wether the UserName is a local or domain account.
You can import the CSV file to a spread sheet, word processor, or data base to produce a nicely formated document. Here is a sample crosstab query made with partial data:
User | Total | Admin-istrators | DomainAdmins | DomainUsers | TestUsers | Users |
---|---|---|---|---|---|---|
JSIAdministrator | 3 | 1 | 1 | 1 | 0 | 0 |
JSIDomain Admins | 1 | 1 | 0 | 0 | 0 | 0 |
JSIDomain Users | 1 | 0 | 0 | 0 | 0 | 1 |
JSIJennifer | 1 | 0 | 0 | 1 | 0 | 0 |
JSIJERRY | 3 | 1 | 1 | 1 | 0 | 0 |
JSITest User | 2 | 0 | 0 | 1 | 1 | 0 |
JSIULTRABAC | 3 | 1 | 1 | 1 | 0 | 0 |
You will notice that this script also outputs global group membership in local groups (JSI/Domain Users is a member of local group Users).
The syntax for running JSIUserRpt.bat is:
JSIUserRpt "csvfile.csv" [Domain Name] where:
Parameter | D e s c r i p t i o n |
---|---|
"csvfile.csv" | The CSV file that will contain the report. |
Domain Name | The Domain Name, using proper case, if JSIUserRpt is run on a Domain Controller. |
JSIUserRpt.bat contains:
<p>@echo off<br>If "%1"</p><h1><a name="_goto_syntax_br_if_exist_1_del_q_1_br_goto_start_br_syntax_br_echo_Syntax_JSIUserRpt_Drive_Path_UserRpt_csv_DomainName_br_goto_end_br_start_br_set_dom_br_if_2_" id="_goto_syntax_br_if_exist_1_del_q_1_br_goto_start_br_syntax_br_echo_Syntax_JSIUserRpt_Drive_Path_UserRpt_csv_DomainName_br_goto_end_br_start_br_set_dom_br_if_2_">"" goto syntax<br>if exist %1 del /q %1<br>goto start<br>:syntax<br>@echo Syntax: JSIUserRpt Drive:PathUserRpt.csv DomainName<br>goto end<br>:start<br>set dom=<br>if "%2"</a></h1>"" goto nodom
set dom=%2
set dom=%dom:"=%
:nodom
if exist %TEMP%UserRpt.log del /q %TEMP%UserRpt.log
net localgroup /domain|Findstr /b /c:"*" >>%TEMP%UserRpt.log
net group /domain|Findstr /b /c:"*" >>%TEMP%UserRpt.log
REM The following is 1 line
for /f "tokens=1-3* delims=*" %%i in (%TEMP%UserRpt.log) do call :group %1 "%%i"&call :group %1 "%%j"&call :group %1 "%%k"
set fix=
set grp=
set tst=
set dom=
goto end
:group
set grp=
set grp=%2
:strips
set fix=%grp%
REM Next line has 10 spaces between the : and the "
set grp=%grp: "="%
REM Next line has 5 spaces between the : and the "
set grp=%grp: "="%
REM Next line has 3 spaces between the : and the "
set grp=%grp: "="%
set grp=%grp: "="%
if %grp%<h1><a name="_goto_end_br_if_grp_" id="_goto_end_br_if_grp_">"" goto end<br>if %grp%</a></h1>%fix% goto goodgrp
goto strips
:goodgrp
for /f "Tokens=1-3*" %%i in ('showmbrs %grp%') do call :users %1 "%%i" "%%j" "%%k" "%%l"
goto end
:users
If not %5<h1><a name="_goto_end_br_set_fix_2_3_4_5_br_set_fix_fix_br_set_fix_fix_br_set_fix_fix_br_set_tst_fix_br_if_not_tst_" id="_goto_end_br_set_fix_2_3_4_5_br_set_fix_fix_br_set_fix_fix_br_set_fix_fix_br_set_tst_fix_br_if_not_tst_">"" goto end<br>set fix=%2%3%4%5<br>set fix=%fix:"""="%<br>set fix=%fix:"""="%<br>set fix=%fix:""= %<br>set tst=%fix:$"="%<br>if not %tst%</a></h1>%fix% goto end
for /f "Tokens=1* Delims=" %%i in (%fix%) do call :bslash "%%i" "%%j"
@echo %grp%,%fix% >> %1
goto end
:bslash
if not %2<h1><a name="_goto_end_br_if_dom_" id="_goto_end_br_if_dom_">"" goto end<br>if "%dom%"</a></h1>"" goto end
set tst="%dom%%fix%
set fix=%tst:"=%
:end
About the Author
You May Also Like