JSI Tip 9135. How can a script process the members of a domain group?

Using only standard commands, I have scripted GetDomGrpMbrs.bat to return a domain groups members.

The syntax for using GetDomGrpMbrs.bat is:

for /f "Tokens=*" %%m in ('call GetDomGrpMbrs "DomainGroup"') do (
 set member=%%m
 call :DoSomething
Where DomainGroup is the NetBIOS domain group that you wish to enumerate, like "Domain Admins".

GetDomGrpMbrs.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax: GetDomGrpMbrs "DomainGroup"&goto :EOF
set grp=%1
for /f "Skip=4 Tokens=*" %%i in ('net group %grp% /domain^|findstr /v /c:"Members"^|findstr /v /c:"----"^|findstr /v /i /c:"The command completed"') do (
 set line=%%i
 call :parse
goto :EOF
set short=%name%#
set short=%short:  =%
set short=%short: #=#%
set short=%short:#=%
@echo %short%
goto :EOF
set name=%line:~0,25%
call :strip
set name=%line:~25,25%
if not "%name%" EQU "" call :strip
set name=%line:~50,25%
if not "%name%" EQU "" call :strip

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