JSI Tip 9346. How can I generate a CSV file of all local group membership?


Using only standard commands, I have scripted EnumLclGrp.bat to output local group membership. The syntax for using EnumLclGrp.bat is:

EnumLclGrp

The output is displayed on the console, but can be redirected to a file using EnumLclGrp>fileName or EnumLclGrp>>fileName.

Each line of output contains:

"Computer Name","Local Group Name","User Name"

EnumLclGrp.bat contains:

@echo off
setlocal ENABLEDELAYEDEXPANSION
for /f "Tokens=*" %%a in ('net localgroup^|findstr /b /l /c:"*"') do (
 set wrk=%%a
 set grp=!wrk:~1!
 for /f "Skip=6 Tokens=*" %%b in ('net localgroup "!grp!"^|find /I /V "The command completed successfully."') do (
  @echo "%ComputerName%","!grp!","%%b"
 )
)
endlocal



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