Skip navigation

JSI Tip 9785. Which distribution groups have no members?


Using ADFind.exe freeware, I have scripted DstGrpNoMbrs.bat to retrieve the distinguishedName of all distribution groups in your domain that do not have members.

To run DstGrpNoMbrs.bat, open a CMD.EXE window and type DstGrpNoMbrs.

DstGrpNoMbrs.bat contains:

@echo Off
setlocal ENABLEDELAYEDEXPANSION
set adf=adfind -default -f "&(objectcategory=group)" grouptype
for /f "Skip=3 Tokens=1* Delims=: " %%a in ('%adf%^|find ":"') do (
 set p1=%%a
 set p1=!p1:~1,1!
 if "!p1!" EQU "n" set dn="%%b"
 set OK=X
 if "!p1!" EQU "g" if "%%b" EQU "2" call :getmbr !dn!>nul 2>&1
 if "!OK!" EQU "N" @echo !dn!
)
endlocal
goto :EOF
:getmbr
set OK=N
for /f "Tokens=*" %%x in ('adfind -nodn -nolabel -b %1 member^|find "="') do (
 set OK=Y
)



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