You are currently offline, waiting for your internet to reconnect

How to Produce a List of Users and SIDs

This article was previously published under Q177077
This article has been archived. It is offered "as is" and will no longer be updated.
This article describes how to produce a sorted list of Windows NT usernames and their corresponding Security Identifiers (SIDs).
The following example will show you how to create a text file that containseach Windows NT Domain User listed with the corresponding SID.

The solution outlined in this article uses the following utilitiescontained in the Windows NT 4.0 Server Resource Kit: Global.exe andGetsid.exe.

  1. Make sure that the Global.exe and Getsid.exe utilities are installed on the computer running Windows NT and are accessible through the system's PATH variable.
  2. Create a directory on the computer running Windows NT that has read/write permissions assigned to the user account you are logging in with.
  3. Create the Listsid.bat, Listsid2.bat, Listsid3.bat, Cleanup.bat and Verify.bat files listed in this article. Create these files in the directory created in Step 2 above.
  4. Execute the Listsid.bat file at an MS-DOS command prompt. The command has the following syntax:

    LISTSID <Domain Name> <Primary Domain Controller Name>

    For Example: LISTSID MyDomain MyPDC
  5. Examine the contents of Usersids.txt.

    Note: These series of batch files were designed to understand a username that can contain as many as three parts separated by spaces. For example, the following name is valid:

    Joe B. Admin

    The following name would not be valid: Joe B. Admin II

    The three batch files could be modified to support names if necessary.
NOTE: The lines in Listsid.bat and Listsid2.bat that begin with "for /F" are wrapped for readibility. If these lines are not corrected before running, the batch jobs will not work.


echo offclsIF (%1)==() GOTO NoParamsIF (%2)==() GOTO NoParamsif exist usersids.txt del usersids.txtif exist domusers.txt del domusers.txtif exist domusers.tmp del domusers.tmpecho Creating list of users in "domain users" %1 > domusers.txtecho Removing machine names from list.for /F "tokens=1,2,3" %%a in (domusers.txt) do call cleanup.bat%%a %%b %%cdel domusers.txtren domusers.tmp domusers.txtecho Getting SIDs from PDC.for /F "tokens=1,2,3" %%a in (domusers.txt) do call listsid2.bat%2 %%a %%b %%cecho Sorting List.  Please wait...sort /+1 < usersids.txt > sortsids.txtecho --------------------------------------------del usersids.txtren sortsids.txt USERSIDS.TXTecho Done!  Outfile file is called: USERSIDS.TXTecho --------------------------------------------goto Bottom:NoParamsEcho usage: LISTSID [Domain Name] [PDC Name]Echo.Echo i.e. - LISTSID RESEARCHDOMAIN RESEARCHPDCEcho.:Bottom				


if exist user.txt del user.txtif not (%4) == () goto ThreeNameif not (%3) == () goto TwoNamegetsid \\%1 %2 \\%1 %2 > user.txtfor /F "skip=2 tokens=7" %%a in (user.txt) do call listsid3.bat%%a %2goto Bottom2:TwoNamegetsid \\%1 "%2 %3" \\%1 "%2 %3" > user.txtfor /F "skip=2 tokens=8" %%a in (user.txt) do call listsid3.bat%%a %2 %3goto Bottom2:ThreeNamegetsid \\%1 "%2 %3 %4" \\%1 "%2 %3 %4" > user.txtfor /F "skip=2 tokens=9" %%a in (user.txt) do call listsid3.bat%%a %2 %3 %4goto Bottom2:Bottom2				


echo Now working on: %2 %3 %4if not (%4) == () goto ThreeNameif not (%3) == () goto TwoNameecho %2 %1 >> usersids.txtGoto Bottom3:TwoNameecho %2 %3 %1 >> usersids.txtGoto Bottom3:ThreeNameecho %2 %3 %4 %1 >> usersids.txt:Bottom3				


if exist onename.txt del onename.txtecho %1 > onename.txtfor /F "delims=$ tokens=1" %%a in (onename.txt) do call verify.bat %%a %1


if (%1)==(%2) echo %1 >> domusers.tmp				
getsid username list sid

Article ID: 177077 - Last Review: 12/05/2015 08:11:20 - Revision: 2.2

Microsoft Windows 2000 Server, Microsoft Windows 2000 Advanced Server, Microsoft Windows 2000 Professional Edition, Microsoft Windows NT Workstation 3.5, Microsoft Windows NT Workstation 3.51, Microsoft Windows NT Workstation 4.0 Developer Edition, Microsoft Windows NT Server 3.5, Microsoft Windows NT Server 3.51, Microsoft Windows NT Server 4.0 Standard Edition

  • kbnosurvey kbarchive kbinfo KB177077