I’m looking for a WMIC solution to obtain a Windows domain's SID. I can only find solutions for PowerShell, however I prefer the WMIC approach.
Lots of examples exist on Google for obtaining domain users’ SID, but none tell how to obtain a computer or domain's SID.
41 Answer
To my knowledge there isn't a "Domain SID" per se. I assume what you're referring to is the Domain Identifier which uniquely identifies a domain within the AD forest.
Each SID in an Active Directory domain includes the Domain Identifier. I'm not aware of a WMIC command that returns only this identifier; however, it's easy to extrapolate it by inspecting any principle's SID in the domain.
For example, the following WMIC command returns the SID of the Domain Admins group:
C:\>wmic group where name="Domain Admins" get name,sid,domain
Domain Name SID
CONTOSO Domain Admins S-1-5-21-1004336348-1177238915-682003330-512As explained in the Microsoft Docs article How Security Identifiers Work, a SID is composed of the following components:
- A revision level (1)
- An identifier authority (5, NT Authority)
- A domain identifier (21-1004336348-1177238915-682003330, Contoso)
- A relative identifier (512, Domain Admins)
Therefore you simply need to strip off the revision level, identifier authority, and RID to derive the Domain Identifier portion.
4