JSI Tip 10615. How can I create a CSV file of all the accounts that are members of the local Administrators group on my workstations and member servers?

I have scripted MbrAdmins.bat to create a Comma Separated Value file that contains the accounts that are members of the local Administrators group on all the workstation and member servers of the domain you are logged onto.

The syntax for using MbrAdmins.bat is:

MbrAdmins Account Password CSVFile


Account   is an account that has administrative privileges on all members, like Administrator.

Password  is the password for Account.

CSVFile   is the CSV file that will be created.


MbrAdmins Administrator AdminPassword c:\reports\MbrAdmins.txt

Sample CSVFile Entry


NOTE: If a member computer is not available, account in the CSV file will be N.

NOTE: MbrAdmins.bat uses the following programs and scripts, which must be present in the PATH of the computer you use to run the script:

       NETDOM.EXE   from the Support Tools of your operating system CD-ROM.

       PsExec.EXE   from tip 4141 » PsExec freeware executes programs remotely.

       CMPAvail.bat from tip 9825 » Another way to test the availability of a remote computer.
                    Because of CMPAvail.bat, you must run the  MbrAdmins.bat script from Windows XP, or Windows Server 2003, or later.
MbrAdmins.bat contains:
@echo off
if \{%3\}==\{\} @echo Syntax: MbrAdmins Account Password ReportFile&goto :EOF
set usr=%1
set pw=%2
set rp=%3
if exist %rp% del /q %rp%
set netdm=netdom query /domain:%userdnsdomain% workstation
set fnd=FIND /i /v "The command completed successfully."
for /f "Skip=1 Tokens=*" %%C in ('%netdm%^|%fnd%') Do call :mbr1 %%C
goto :EOF
call CMPAvail %1 OK
if "%OK%" EQU "Y" goto mbr2
@echo "\\%1","N">>%rp%
goto :EOF
set cmp=\\%1
if exist "%TEMP%\MbrAdmins.tmp" del /q "%TEMP%\MbrAdmins.tmp"
call :mbr3>nul 2>&1
if not exist "%TEMP%\MbrAdmins.tmp" goto :EOF
for /f "Skip=6 Tokens=*" %%x in ('type  "%TEMP%\MbrAdmins.tmp"^|%fnd%') do (
 @echo "%cmp%","%%x">>%rp%
if exist "%TEMP%\MbrAdmins.tmp" del /q "%TEMP%\MbrAdmins.tmp"
goto :EOF
psExec %cmp% -u %usr% -p %pw% net localgroup Administrators>"%TEMP%\MbrAdmins.tmp"

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.