The following script will echo the current user’s SID:

FOR /F "tokens=2" %%a in ('whoami /user /fo table /nh') do SET SID=%%a
echo %sid%

The following script will echo any user’s SID that you typed in:

SET /P USERNAME_PROFILE="Enter the username here: "

reg query "HKLM\software\microsoft\windows nt\currentversion\profilelist" /s >>reg_sid.txt
findstr /n /i %USERNAME_PROFILE% reg_sid.txt>>sid_number.txt 
for /f "tokens=1 delims=:" %%i in (sid_number.txt) do set line_num=%%i
set /a line_num=%line_num% - 2 
for /f "skip=%line_num% tokens=7 delims=\" %%i in (reg_sid.txt) do set sid=%%i & goto :continue 
for /f "tokens=* delims= " %%A in ('echo %SID%') do set SID=%%A
set SID=%SID:~0,-1%
del reg_sid.txt 
del sid_number.txt