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 setlocal 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" endlocal goto :EOF :getpg set usr=%usr: =% set usr=%usr: "="% call primaryGroupId %pgi% pgidn @echo %pgidn%#%usr%>>"%TEMP%\userpgid.tmp"
0 comments
Hide comments