JSI Tip 8475. Generate a sorted Primary Group / User report.

Using information from tip 6337 ยป A user's Member attribute is NOT populated with the Primary Group, the Active Directory command-line tools, and primaryGroupID.bat, I have scripted UserPGID.bat to display the distinguished name of the primaryGroupID and the user's distinguished name.

The output is displayed on the console, but you can process it in your script using:

for /f "Tokens=1* Delims=#" %%a in ('userpgid') do (
 set group=%%a
 set user=%%b
UserPGID.bat contains:
@echo off
if exist "%TEMP%\userpgid.tmp" del /q "%TEMP%\userpgid.tmp"
set qry=dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User))" -attr primaryGroupId distinguishedName -limit 0
for /f "Skip=1 Tokens=1*" %%a in ('%qry%') do (
 set pgi=%%a
 set usr="%%b"
 call :getpg
sort "%TEMP%\userpgid.tmp"
del /q "%TEMP%\userpgid.tmp"
goto :EOF
set usr=%usr:  =%
set usr=%usr: "="%
call primaryGroupId %pgi% pgidn
@echo %pgidn%#%usr%>>"%TEMP%\userpgid.tmp"

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.