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?
Jerold Schulman
June 27, 2006
1 Min Read
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
where:
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.
Example
MbrAdmins Administrator AdminPassword c:reportsMbrAdmins.txt
Sample CSVFile Entry
"\JSI007","JSIINCJennifer"
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 offif {%3}=={} @echo Syntax: MbrAdmins Account Password ReportFile&goto :EOFsetlocalset usr=%1set pw=%2set rp=%3if exist %rp% del /q %rp%set netdm=netdom query /domain:%userdnsdomain% workstationset fnd=FIND /i /v "The command completed successfully."for /f "Skip=1 Tokens=*" %%C in ('%netdm%^|%fnd%') Do call :mbr1 %%Cendlocalgoto :EOF:mbr1call CMPAvail %1 OKif "%OK%" EQU "Y" goto mbr2@echo "\%1","N">>%rp%goto :EOF:mbr2set cmp=\%1if exist "%TEMP%MbrAdmins.tmp" del /q "%TEMP%MbrAdmins.tmp"call :mbr3>nul 2>&1if not exist "%TEMP%MbrAdmins.tmp" goto :EOFfor /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:mbr3psExec %cmp% -u %usr% -p %pw% net localgroup Administrators>"%TEMP%MbrAdmins.tmp"
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like