Batch – Return Computer SID

email me

@echo off

:: goto :three

:one
for /f "delims= " %%a in ('"wmic path win32_useraccount where name='administrator' get sid"') do (
   if not "%%a"=="SID" (          
      set myvar=%%a
      goto :loop_end
   )   
)

:loop_end
echo %myvar%
pause

:two
for /F "tokens=2" %%i in ('whoami /user /fo table /nh') do set usersid=%%i
echo %usersid%
pause

:three
FOR /F "tokens=1,2 delims==" %%s IN ('wmic path win32_useraccount where name^='administrator' get sid /value ^| find /i "SID"') DO SET SID=%%t
set RootSID=%SID:~0,-5%
echo %RootSID%
pause