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


I have scripted MbrSvrAdmins.bat to create a Comma Separated Value file that contains the accounts that are members of the local Administrators group on my member servers.

The syntax for using MbrSvrAdmins.bat is:

MbrSvrAdmins Account Password CSVFile

where:

Account   is an account that has administrative privileges on all member servers, like a member of the Domain Admins group.

Password  is the password for Account.

CSVFile   is the CSV file that will be created.

Example

MbrSvrAdmins JSIINC\Jerry MyPassword c:\reports\MbrSvrAdmins.txt

Sample CSVFile Entry

"\\JSI007","JSIINC\Jennifer"

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

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

       REG.EXE, built into Windows XP, Windows Server 200x, or installed from the Support Tools of your Windows 2000 CD-ROM.

       PsExec.EXE from  tip 4141 ยป PsExec freeware executes programs remotely.
MbrSvrAdmins.bat contains:
@echo off
if \{%3\}==\{\} @echo Syntax: MbrSvrAdmins Account Password ReportFile&goto :EOF
setlocal
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
endlocal
goto :EOF
:mbr1
for /f "Tokens=*" %%x in ('@ping -n 1 %1^|FIND /i "TTL"') do goto mbr2
goto :EOF
:mbr2
set cmp=\\%1
set OK=N
for /f "Tokens=2*" %%x in ('reg query "%cmp%\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /V ProductName^|FIND "REG_SZ"') do (
 set pName=%%y
 set OK=Y
)
if "%OK%" EQU "N" goto :EOF
for /f "Tokens=*" %%x in ('@echo %pName%^|FIND /v /i "Server"') do goto :EOF
if exist "%TEMP%\MbrSvrAdmins.tmp" del /q "%TEMP%\MbrSvrAdmins.tmp"
call :mbr3>nul 2>&1
if not exist "%TEMP%\MbrSvrAdmins.tmp" goto :EOF
for /f "Skip=6 Tokens=*" %%x in ('type  "%TEMP%\MbrSvrAdmins.tmp"^|%fnd%') do (
 @echo "%cmp%","%%x">>%rp%
)
if exist "%TEMP%\MbrSvrAdmins.tmp" del /q "%TEMP%\MbrSvrAdmins.tmp"
goto :EOF
:mbr3
psExec %cmp% -u %usr% -p %pw% net localgroup Administrators>"%TEMP%\MbrSvrAdmins.tmp"



Hide comments

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.
Publish