SCRIPT: Get a User's SID

GETSID

PsGetSid

Examples:

1- [http://windowsitpro.com/article/articleid/76649/jsi-tip-5345-how-can-i-get-a-users-sid-in-a-batch-file.html JSI Tip 5345. How can I get a user's SID in a batch file?]

Using the public domain GETSID.EXE, I have scripted UserSID.bat. The syntax for using UserSID.bat is:

call usersid \\computername UserName

where:

\\ComputerName is either a domain controller, if you want the domain SID, or the local workstation, if the UserName is local.

UserName is the User Account whose SID you want.

UserSID.bat returns the SID in the sid environment variable, %sid%.

NOTE: UserSID.bat will NOT work if the UserName contains spaces.

UserSID.bat contains:

@echo off set sid= If {%2}=={} goto syntax if not exist %1\c$ goto syntax for /f "Skip=2 Tokens=7" %%i in ('getsid %1 %2 %1 %2') do set sid=%%i goto :EOF
 * syntax

@echo Syntax call UserSID \\DC_or_Local UserName

2- Handy VBS script :

Dim UName UName = InputBox("Enter The User Name :","Username To SID","E0")

strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set objAccount = objWMIService.Get _ ("Win32_UserAccount.Name='" & UName & "',Domain='DOMAIN NETBIOS NAME'") Wscript.Echo objAccount.SID