JSI Tip 7729. How can I convert a primaryGroupId to a group name in a script?

NOTE: See When you inspect the value of a user's primaryGroupID, in DSQUERY, you only see a number?

Using the ListGroupRID.bat script, I have scripted GetPGID.bat, which you can use to convert primaryGroupID to a group name, while you are processing the results of a query.

The syntax for using GetPGID.bat is:

call GetPGID primaryGroupId GroupName

Where primaryGroupId is the group RID and GroupName is a call directed environment variable that will contain the group name, encapsulated in quote marks (").

GetPGID.bat contains:

@echo off
if \{%2\}==\{\} @echo Syntax: call GetPGID primaryGroupId GroupName&exit /b 1
set PGID="%TEMP%\%ComputerName%_%UserName%_GetPGID.tmp"
if not exist %PGID% ListGroupRID>%PGID%
set %2="Unknown"
for /f "Tokens=1*" %%f in ('findstr /C:%1 %PGID%') do if "%1" EQU "%%f" set %2=%%g
exit /b 0

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.