Q. How can I use a script to check an object's SID?

A. The script below uses WMI to query the object's SID. In this example, I'm checking user John in domain savilltech. You can change these values to any object. Instead of a domain, you can use a computer name to get SIDs for local machine objects.

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

Set objAccount = objWMIService.Get _
("Win32_Account.Name='john',Domain='savilltech'")
Wscript.Echo objAccount.SID

Here is the result.

cscript getusersid.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
S-1-5-21-2835294230-785241407-2532694646-1106

Essentially, this script is a WMI lookup, outputting the object's SID attribute.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish