JSI Tip 9362. How can I generate a CSV file of domain group membership?

Jerold Schulman

May 17, 2005

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

In tip 9346, we generated a CSV file of local group membership.

Using the NET GROUP command, I have scripted NetGroup.bat to generate a CSV format output on the console, that contains:

"Computer Name","Group Name","Member Name"

NOTE: To redirect the output to a CSV file, use NetGroup>FileName.CSV.

NOTE: See What Active Directory groups exist that are not enumerated by the 'net group /domain' command?

NetGroup.bat contains:

@echo offsetlocal ENABLEDELAYEDEXPANSIONfor /f "Tokens=*" %%a in ('net group /domain^|findstr /b /l /c:"*"') do ( set wrk=%%a set grp=!wrk:~1! for /f "Skip=8 Tokens=*" %%i in ('net group "!grp!" /domain^|find /V /I "The command completed successfully."') do (  set line=%%i  call :parse ))endlocalgoto :EOF:stripset short=%name%#set short=%short:  =%set short=%short: #=#%set short=%short:#=%@echo "%ComputerName%","!grp!","%short%"goto :EOF:parseset name=%line:~0,25%call :stripset name=%line:~25,25%if not "%name%" EQU "" call :stripset name=%line:~50,25%if not "%name%" EQU "" call :strip



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