JSI Tip 8990. How can I report local Administrators group membership for all the computers in my network?

Jerold Schulman

January 30, 2005

1 Min Read
ITPro Today logo in a gray background | ITPro Today

Using PsExec.exe, I have scripted LocalAdmins.bat to report local Administrators group membership for all the computers in my network.

The syntax for using LocalAdmins.bat is:

\HostShareLocalAdmins.bat Account Password

where:

Host     is a computer that will host the LocalAdmins.bat script and the LocalAdmins.log report file in it's Share.Share    is a share name on Host that is writeable by Account.Account  is an account that has administrative privileges on all the computers in your network.Password is the password of Account.

Sample Usage:

\jsi001etlogonLocalAdmins.bat JSIINCJerry

The resulting \jsi001etlogonLocalAdmins.log report might contain:

JSI001 AdministratorJSI001 Domain AdminsJSI001 Enterprise AdminsJSI005 AdministratorJSI005 JSIINCDomain AdminsJSI007 AdministratorJSI007 JSIINCDomain AdminsJSI007 JSIINCJenniferJSI009 AdministratorJSI009 JSIINCDomain AdminsJSI009 JSIINCJerry

NOTE: You must copy PsExec.exe to \HostSharePsexec.exe.

LocalAdmins.bat contains:

@echo offif {%2}=={} @echo Syntax: LocalAdmins DomainAdminAccount DomainAdminPassword&goto :EOFsetlocalset batch=%~DP0LocalAdminsBat.batset report=%~DP0LocalAdmins.logset PsExec=%~DP0PsExec.exeset domacct=%1set pw=%2@echo @echo off>%batch%@echo setlocal>>%batch%@echo for /f "Skip=6 Tokens=*" %%%%m in ('net localgroup administrators^^^|FIND /V /I "The command completed successfully."') Do @echo ^%%computername^%% %%%%m>>%batch%@echo endlocal>>%batch%if exist %report% del /q %report%call :quiet>nul 2>&1del /q %batch%endlocalgoto :EOF:quietfor /f "Tokens=1" %%c in ('net view^|FIND "\"') do ( %PsExec% %%c -u %domacct% -p %pw% %batch%>>%Report%)



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