How to get a server’s machine SID

Anonymous KH
Anonymous KH used Ask the Experts™
on
What is the WMIC command to get the Server/machine SID, not the domain SID?

I keep reading how to get useracoount SID or using Powershell.

What I require is using WMIC command only.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
dsquery * -Filter "(name=MyComputer)" -attr objectSID

Or

dsquery computer -name "MyComputer" | dsget computer -SID

all the best
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
You query for the local user account SID ending with -500 (default administrator), and get rid of the -500; that's the local computer SID.
Plain wmic query returning the local Administrator's SID:
wmic.exe useraccount WHERE "(Sid LIKE '%%-500') AND (Domain='%ComputerName%')" GET Sid /value

Open in new window

Batch script returning the computer's SID:
@echo off
setlocal
for /f "delims=" %%a in ('wmic.exe useraccount WHERE "(Sid LIKE '%%-500') AND (Domain='%ComputerName%')" GET Sid /value') do (for /f "delims=" %%b in ("%%a") do set %%b)
set ComputerSid=%SID:~0,-4%
echo %ComputerSid%

Open in new window

Neil PettyICT Contractor
Commented:
You may find the freeware tool WMI Explorer useful : https://archive.codeplex.com/?p=wmie/

It has examples of WMI lookups VBScript, Powershell
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:
Note: oBdA's comment is correct, as long as you are running it on the machine to check. For remote execution, we would need significantly more effort, but that is probably out of scope of this question.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial